summaryrefslogtreecommitdiffhomepage
path: root/benchmarks/cdeq_benchmark.cpp
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-11 19:12:45 +0100
committerTyge Løvset <[email protected]>2021-02-11 19:12:45 +0100
commite6ea4740c9fad4a9453fb62432ef238d2761271c (patch)
tree9ed659c2857c99a6b8d25bbdf34523868a112c33 /benchmarks/cdeq_benchmark.cpp
parentdebbd4efac5cea9b71468d36f7f11ab9b25837b9 (diff)
downloadSTC-modified-e6ea4740c9fad4a9453fb62432ef238d2761271c.tar.gz
STC-modified-e6ea4740c9fad4a9453fb62432ef238d2761271c.zip
Updated benchmarks
Diffstat (limited to 'benchmarks/cdeq_benchmark.cpp')
-rw-r--r--benchmarks/cdeq_benchmark.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/benchmarks/cdeq_benchmark.cpp b/benchmarks/cdeq_benchmark.cpp
index ff1c9361..52e829ff 100644
--- a/benchmarks/cdeq_benchmark.cpp
+++ b/benchmarks/cdeq_benchmark.cpp
@@ -5,15 +5,15 @@
#ifdef __cplusplus
#include <deque>
+#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 = 100000000};
-
-uint64_t seed = 1, mask1 = 0xfffffff;
+enum {SAMPLES = 2, N = 100000000, S = 0x3ffc};
+uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
@@ -39,9 +39,16 @@ Sample test_std_deque() {
}{
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;
@@ -64,9 +71,9 @@ Sample test_stc_deque() {
container con = cdeq_x_init();
//cdeq_x_reserve(&con, N);
stc64_srandom(seed);
- c_forrange (N/2) cdeq_x_push_front(&con, stc64_random() & mask1);
- c_forrange (N/2) { cdeq_x_push_back(&con, stc64_random() & mask1); cdeq_x_pop_front(&con); }
- c_forrange (N/2) cdeq_x_push_back(&con, stc64_random() & mask1);
+ c_forrange (N/3) cdeq_x_push_front(&con, stc64_random() & mask1);
+ c_forrange (N/3) { cdeq_x_push_back(&con, stc64_random() & mask1); cdeq_x_pop_front(&con); }
+ c_forrange (N/3) cdeq_x_push_back(&con, stc64_random() & mask1);
s.test[INSERT].t2 = clock();
s.test[INSERT].sum = cdeq_x_size(con);
s.test[ERASE].t1 = clock();
@@ -77,9 +84,15 @@ Sample test_stc_deque() {
}{
stc64_srandom(seed);
container con = cdeq_x_init();
- c_forrange (N) cdeq_x_push_back(&con, stc64_random() & mask1);
- s.test[ITER].t1 = clock();
+ c_forrange (N) cdeq_x_push_back(&con, stc64_random() & mask2);
+ s.test[FIND].t1 = clock();
size_t sum = 0;
+ cdeq_x_iter_t it;
+ //c_forrange (S) if ((it = cdeq_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 += *cdeq_x_at(&con, i);
s.test[ITER].t2 = clock();
s.test[ITER].sum = sum;
@@ -103,11 +116,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);
}