[ create a new paste ] login | about

Link: http://codepad.org/7OMgUQxY    [ raw code | fork ]

Plain Text, pasted on Feb 16:
tronic@Kaidenn:/tmp$ for foo in `seq 3`; do echo Test $foo && g++ vec.cc -O3 -DTEST=$foo && time ./a.out; done
Test 1

real	0m7.341s
user	0m7.310s
sys	0m0.030s
Test 2

real	0m7.329s
user	0m7.310s
sys	0m0.010s
Test 3

real	0m7.392s
user	0m7.360s
sys	0m0.030s
tronic@Kaidenn:/tmp$ cat vec.cc
#include <vector>

int main() {
	int ret = 0;
	std::vector<int> vec(10000000, 3);
	for (int r = 0; r < 1000; ++r) {
#if TEST==1
		for (size_t i = 0; i < vec.size(); ++i) ret += vec.at(i); // With bounds checking
#elif TEST==2
		for (size_t i = 0; i < vec.size(); ++i) ret += vec[i]; // Without bounds checking
#elif TEST==3
		for (size_t i = 0, max = vec.size(); i < max; ++i) ret += vec[i]; // Optimized by hand
#endif
	}
	return ret;
}



Create a new paste based on this one


Comments: