summaryrefslogtreecommitdiffhomepage
path: root/benchmarks/cvec_benchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/cvec_benchmark.cpp')
-rw-r--r--benchmarks/cvec_benchmark.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/benchmarks/cvec_benchmark.cpp b/benchmarks/cvec_benchmark.cpp
index e7a4c869..c208b3a2 100644
--- a/benchmarks/cvec_benchmark.cpp
+++ b/benchmarks/cvec_benchmark.cpp
@@ -5,15 +5,15 @@
#ifdef __cplusplus
#include <vector>
+#include <algorithm>
#endif
enum {INSERT, ERASE, FIND, ITER, DESTRUCT, N_TESTS};
const char* operations[] = {"insert", "erase", "find", "iter", "destruct"};
typedef struct { time_t t1, t2; uint64_t sum; float fac; } Range;
typedef struct { const char* name; Range test[N_TESTS]; } Sample;
-enum {SAMPLES = 3, N = 150000000};
-
-uint64_t seed = 1, mask1 = 0xfffffff;
+enum {SAMPLES = 2, N = 150000000, S = 0x3ffc};
+uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
@@ -37,9 +37,16 @@ Sample test_std_vector() {
}{
container con;
stc64_srandom(seed);
- c_forrange (N) con.push_back(stc64_random() & mask1);
- s.test[ITER].t1 = clock();
+ c_forrange (N) con.push_back(stc64_random() & mask2);
+ s.test[FIND].t1 = clock();
size_t sum = 0;
+ container::iterator it;
+ // Iteration - not inherent find - skipping
+ //c_forrange (S) if ((it = std::find(con.begin(), con.end(), stc64_random() & mask2)) != con.end()) sum += *it;
+ s.test[FIND].t2 = clock();
+ s.test[FIND].sum = sum;
+ s.test[ITER].t1 = clock();
+ sum = 0;
c_forrange (i, N) sum += con[i];
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
@@ -73,9 +80,15 @@ Sample test_stc_vector() {
}{
stc64_srandom(seed);
container con = cvec_x_init();
- c_forrange (N) cvec_x_push_back(&con, stc64_random() & mask1);
- s.test[ITER].t1 = clock();
+ c_forrange (N) cvec_x_push_back(&con, stc64_random() & mask2);
+ s.test[FIND].t1 = clock();
size_t sum = 0;
+ cvec_x_iter_t it;
+ //c_forrange (S) if ((it = cvec_x_find(&con, stc64_random() & mask2)).ref) sum += *it.ref;
+ s.test[FIND].t2 = clock();
+ s.test[FIND].sum = sum;
+ s.test[ITER].t1 = clock();
+ sum = 0;
c_forrange (i, N) sum += *cvec_x_at(&con, i);
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
@@ -99,11 +112,13 @@ int main(int argc, char* argv[])
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
}
}
+ const char* comp = argc > 1 ? argv[1] : "test";
+ bool header = (argc > 2 && argv[2][0] == '1');
float std_sum = 0, stc_sum = 0;
c_forrange (j, N_TESTS) { std_sum += secs(std_s[0].test[j]); stc_sum += secs(stc_s[0].test[j]); }
- if (argv[1][0] == '1') printf("compiler,library,container,count,operation,time,ratio\n");
- c_forrange (j, N_TESTS) printf("%s,%s,%d,%s,%.3f,%.3f\n", argv[2], std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
- printf("%s,%s,%d,%s,%.3f,%.3f\n", argv[2], std_s[0].name, N, "total", std_sum, 1.0f);
- c_forrange (j, N_TESTS) printf("%s,%s,%d,%s,%.3f,%.3f\n", argv[2], stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
- printf("%s,%s,%d,%s,%.3f,%.3f\n", argv[2], stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
+ if (header) printf("Compiler,Library,C,Method,Seconds,Ratio\n");
+ c_forrange (j, N_TESTS) printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, operations[j], secs(std_s[0].test[j]), 1.0f);
+ printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, std_s[0].name, N, "total", std_sum, 1.0f);
+ c_forrange (j, N_TESTS) printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, operations[j], secs(stc_s[0].test[j]), secs(std_s[0].test[j]) ? secs(stc_s[0].test[j])/secs(std_s[0].test[j]) : 1.0f);
+ printf("%s,%s n:%d,%s,%.3f,%.3f\n", comp, stc_s[0].name, N, "total", stc_sum, stc_sum/std_sum);
}