source: tests/zombies/vector-perf/iteration-perf.cfa

Last change on this file was 44856ed, checked in by Michael Brooks <mlbrooks@…>, 12 months 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: 1.1 KB
Line 
1#include "vector2.hfa"
2
3#include <time.h>
4
5enum { NumElements = 10000, NumReps = 50000 };
6
7// A layer of indirection to improve performance (naturally!)
8// Works around trac #248.
9// This test keeps a vector of notfloat, instead of a vector of float.  The optimizer removes this added indirection.
10// Furthermore, by passing notfloat's static-inline constructors, defined in this compile unit, to vector, the vector's element's constructors become eligible for inlining.
11// Skipping this optimization costs about a 25% slowdown.
12struct notfloat{ inline float; };
13
14int main() {
15    clock_t start, end;
16    vector(notfloat) x = { 4 };
17    for (i; NumElements) {
18        push_last(x, (notfloat){0.1f * i});
19    }
20    float total;
21    start = clock();
22    for (rep; NumReps) {
23        total = 0;
24        while( vector_exit(notfloat) it = x`origin; it`moveNext ) {
25            total += it`val;
26        }
27    }
28    end = clock();
29    printf("last total was %f\n", total);
30    double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; \
31    printf("iterating duration was %f\n", elapsed);
32}
Note: See TracBrowser for help on using the repository browser.