- Sequential access faster than random
- Instructions should not have dependencies, e.g.
Slow:
a += 1
b += a
c += b
d += c
Fast:
a += 1
b += 1
c += 1
d += 1
If you know the size in advance, you can put things faster with direct index.
Slow:
std::vector<double> numbers;
for (int i = 0; i < 100; i++) {
numbers.push_back(10);
}
Fast:
std::vector<double> numbers (100);
for (int i = 0; i < 100; i++) {
numbers[i] = 10;
}
int dataSize = 10000;
float *floatData;
floatData = (float *)malloc(sizeof(float)*dataSize);
std::copy(data, data + dataSize, floatData);