source: tests/zombies/vector-perf/iteration-perf.cpp @ acb38ce9

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since acb38ce9 was 44856ed, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Baseline "new" vector, with iterators.

Implementation has not had thorough correctness testing, e.g. checking wraparound
behaviours, and at least one such case is commented as unimplemented.

Implementation has not been optimized at the instruction path level, though a basic
iteration performance check has it within 5% of c++ std::vector.

  • Property mode set to 100644
File size: 689 bytes
RevLine 
[44856ed]1#include <vector>
2#include <iostream>
3#include <time.h>
4
5enum { NumElements = 10000, NumReps = 50000 };
6
7int main() {
8    clock_t start, end;
9    std::vector<float> x;
10    for (int i = 0; i < NumElements; i++) {
11        x.push_back(0.1f * i);
12    }
13    float total;
14    start = clock();
15    for (int rep = 0; rep < NumReps; rep++) {
16        total = 0;
17        for( std::vector<float>::iterator it = x.begin(); it < x.end(); it ++ ) {
18            total += *it;
19        }
20    }
21    end = clock();
22    std::cout << "last total was " << total << std::endl;
23    double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; \
24    std::cout << "iterating duration was " << elapsed << std::endl;
25}
Note: See TracBrowser for help on using the repository browser.