Should all callgrind bottlenecks be optimized? (December 10, 2010)
Hey all,
I’d like to have some feedback from you. Consider this code:
#include <iostream>
#include <memory.h>
using namespace std;
struct List {
List(int size) {
begin = new int[size];
memset(begin, 0, size);
end = begin + size;
}
~List() {
delete[] begin;
}
int at(int i) const {
return begin[i];
}
int size() const {
// std::cout << "size called" << std::endl;
return end - begin;
}
int& operator[](int i) {
return begin[i];
}
private:
int* begin;
int* end;
};
int main() {
const int s = 1000000;
for (int reps = 0; reps < 1000; ++reps) {
List l(s);
List l2(s);
// version 1
for ( int i = 0; i < l.size(); ++i ) {
// version 2
// for ( int i = 0, c = l.size(); i < c; ++i ) {
l2[i] = l.at(i);;
}
}
return 0;
}