#include #include #include enum { NumElements = 10000, NumReps = 50000 }; int main() { clock_t start, end; std::vector x; for (int i = 0; i < NumElements; i++) { x.push_back(0.1f * i); } float total; start = clock(); for (int rep = 0; rep < NumReps; rep++) { total = 0; for( std::vector::iterator it = x.begin(); it < x.end(); it ++ ) { total += *it; } } end = clock(); std::cout << "last total was " << total << std::endl; double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; \ std::cout << "iterating duration was " << elapsed << std::endl; }