diff options
| author | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
| commit | de629774cb912aa3d563f24d99258142713c3fcd (patch) | |
| tree | c37e2851d6cb049bc0863a59b6ecf5945fb88619 /benchmarks/plotbench | |
| parent | 7fb43a24a17da787dd809114ca26c1231b058493 (diff) | |
| download | STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.tar.gz STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.zip | |
Converted all files with DOS line endings to LINUX.
Diffstat (limited to 'benchmarks/plotbench')
| -rw-r--r-- | benchmarks/plotbench/cdeq_benchmark.cpp | 260 | ||||
| -rw-r--r-- | benchmarks/plotbench/clist_benchmark.cpp | 252 | ||||
| -rw-r--r-- | benchmarks/plotbench/cmap_benchmark.cpp | 266 | ||||
| -rw-r--r-- | benchmarks/plotbench/cpque_benchmark.cpp | 142 | ||||
| -rw-r--r-- | benchmarks/plotbench/csmap_benchmark.cpp | 270 | ||||
| -rw-r--r-- | benchmarks/plotbench/cvec_benchmark.cpp | 252 |
6 files changed, 721 insertions, 721 deletions
diff --git a/benchmarks/plotbench/cdeq_benchmark.cpp b/benchmarks/plotbench/cdeq_benchmark.cpp index 057a50b8..d938450a 100644 --- a/benchmarks/plotbench/cdeq_benchmark.cpp +++ b/benchmarks/plotbench/cdeq_benchmark.cpp @@ -1,130 +1,130 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#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 = 2, N = 100000000, S = 0x3ffc, R = 4};
-uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
-
-static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-
-#define i_tag x
-#define i_val size_t
-#include <stc/cdeq.h>
-
-#ifdef __cplusplus
-Sample test_std_deque() {
- typedef std::deque<size_t> container;
- Sample s = {"std,deque"};
- {
- s.test[INSERT].t1 = clock();
- container con;
- csrandom(seed);
- c_forrange (N/3) con.push_front(crandom() & mask1);
- c_forrange (N/3) {con.push_back(crandom() & mask1); con.pop_front();}
- c_forrange (N/3) con.push_back(crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = con.size();
- s.test[ERASE].t1 = clock();
- c_forrange (con.size()/2) { con.pop_front(); con.pop_back(); }
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = con.size();
- }{
- container con;
- csrandom(seed);
- c_forrange (N) con.push_back(crandom() & mask2);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- // Iteration - not inherent find - skipping
- //container::iterator it;
- //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con[i];
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-#else
-Sample test_std_deque() { Sample s = {"std-deque"}; return s;}
-#endif
-
-
-Sample test_stc_deque() {
- typedef cdeq_x container;
- Sample s = {"STC,deque"};
- {
- s.test[INSERT].t1 = clock();
- container con = cdeq_x_init();
- //cdeq_x_reserve(&con, N);
- csrandom(seed);
- c_forrange (N/3) cdeq_x_push_front(&con, crandom() & mask1);
- c_forrange (N/3) {cdeq_x_push_back(&con, crandom() & mask1); cdeq_x_pop_front(&con);}
- c_forrange (N/3) cdeq_x_push_back(&con, crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = cdeq_x_size(con);
- s.test[ERASE].t1 = clock();
- c_forrange (cdeq_x_size(con)/2) { cdeq_x_pop_front(&con); cdeq_x_pop_back(&con); }
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = cdeq_x_size(con);
- cdeq_x_drop(&con);
- }{
- csrandom(seed);
- container con = cdeq_x_init();
- c_forrange (N) cdeq_x_push_back(&con, crandom() & mask2);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- //cdeq_x_iter it, end = cdeq_x_end(&con);
- //c_forrange (S) if ((it = cdeq_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con.data[i];
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- cdeq_x_drop(&con);
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-
-int main(int argc, char* argv[])
-{
- Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (i, int, SAMPLES) {
- std_s[i] = test_std_deque();
- stc_s[i] = test_stc_deque();
- if (i > 0) c_forrange (j, int, N_TESTS) {
- if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
- if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
- 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 (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);
-}
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#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 = 2, N = 100000000, S = 0x3ffc, R = 4}; +uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff; + +static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } + +#define i_tag x +#define i_val size_t +#include <stc/cdeq.h> + +#ifdef __cplusplus +Sample test_std_deque() { + typedef std::deque<size_t> container; + Sample s = {"std,deque"}; + { + s.test[INSERT].t1 = clock(); + container con; + csrandom(seed); + c_forrange (N/3) con.push_front(crandom() & mask1); + c_forrange (N/3) {con.push_back(crandom() & mask1); con.pop_front();} + c_forrange (N/3) con.push_back(crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = con.size(); + s.test[ERASE].t1 = clock(); + c_forrange (con.size()/2) { con.pop_front(); con.pop_back(); } + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = con.size(); + }{ + container con; + csrandom(seed); + c_forrange (N) con.push_back(crandom() & mask2); + s.test[FIND].t1 = clock(); + size_t sum = 0; + // Iteration - not inherent find - skipping + //container::iterator it; + //c_forrange (S) if ((it = std::find(con.begin(), con.end(), crandom() & mask2)) != con.end()) sum += *it; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_forrange (i, N) sum += con[i]; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} +#else +Sample test_std_deque() { Sample s = {"std-deque"}; return s;} +#endif + + +Sample test_stc_deque() { + typedef cdeq_x container; + Sample s = {"STC,deque"}; + { + s.test[INSERT].t1 = clock(); + container con = cdeq_x_init(); + //cdeq_x_reserve(&con, N); + csrandom(seed); + c_forrange (N/3) cdeq_x_push_front(&con, crandom() & mask1); + c_forrange (N/3) {cdeq_x_push_back(&con, crandom() & mask1); cdeq_x_pop_front(&con);} + c_forrange (N/3) cdeq_x_push_back(&con, crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = cdeq_x_size(con); + s.test[ERASE].t1 = clock(); + c_forrange (cdeq_x_size(con)/2) { cdeq_x_pop_front(&con); cdeq_x_pop_back(&con); } + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = cdeq_x_size(con); + cdeq_x_drop(&con); + }{ + csrandom(seed); + container con = cdeq_x_init(); + c_forrange (N) cdeq_x_push_back(&con, crandom() & mask2); + s.test[FIND].t1 = clock(); + size_t sum = 0; + //cdeq_x_iter it, end = cdeq_x_end(&con); + //c_forrange (S) if ((it = cdeq_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_forrange (i, N) sum += con.data[i]; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + cdeq_x_drop(&con); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} + +int main(int argc, char* argv[]) +{ + Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; + c_forrange (i, int, SAMPLES) { + std_s[i] = test_std_deque(); + stc_s[i] = test_stc_deque(); + if (i > 0) c_forrange (j, int, N_TESTS) { + if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; + if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; + 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 (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); +} diff --git a/benchmarks/plotbench/clist_benchmark.cpp b/benchmarks/plotbench/clist_benchmark.cpp index dfa043f0..0f5a3f8f 100644 --- a/benchmarks/plotbench/clist_benchmark.cpp +++ b/benchmarks/plotbench/clist_benchmark.cpp @@ -1,127 +1,127 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#ifdef __cplusplus
-#include <forward_list>
-#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 = 2, N = 50000000, S = 0x3ffc, R = 4};
-uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
-
-static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-
-#define i_val size_t
-#define i_tag x
-#include <stc/clist.h>
-
-#ifdef __cplusplus
-Sample test_std_forward_list() {
- typedef std::forward_list<size_t> container;
- Sample s = {"std,forward_list"};
- {
- s.test[INSERT].t1 = clock();
- container con;
- csrandom(seed);
- c_forrange (N/2) con.push_front(crandom() & mask1);
- c_forrange (N/2) con.push_front(crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = 0;
- s.test[ERASE].t1 = clock();
- c_forrange (N) con.pop_front();
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = 0;
- }{
- container con;
- csrandom(seed);
- c_forrange (N) con.push_front(crandom() & 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(), crandom() & mask2)) != con.end()) sum += *it;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) for (auto i: con) sum += i;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-#else
-Sample test_std_forward_list() { Sample s = {"std-forward_list"}; return s;}
-#endif
-
-
-Sample test_stc_forward_list() {
- typedef clist_x container;
- Sample s = {"STC,forward_list"};
- {
- s.test[INSERT].t1 = clock();
- container con = clist_x_init();
- csrandom(seed);
- c_forrange (N/2) clist_x_push_front(&con, crandom() & mask1);
- c_forrange (N/2) clist_x_push_back(&con, crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = 0;
- s.test[ERASE].t1 = clock();
- c_forrange (N) clist_x_pop_front(&con);
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = 0;
- clist_x_drop(&con);
- }{
- csrandom(seed);
- container con = clist_x_init();
- c_forrange (N) clist_x_push_front(&con, crandom() & mask2);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- //clist_x_iter it, end = clist_x_end(&con);
- //c_forrange (S) if ((it = clist_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_foreach (i, clist_x, con) sum += *i.ref;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- clist_x_drop(&con);
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-
-int main(int argc, char* argv[])
-{
- Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (i, int, SAMPLES) {
- std_s[i] = test_std_forward_list();
- stc_s[i] = test_stc_forward_list();
- if (i > 0) c_forrange (j, int, N_TESTS) {
- if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
- if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
- 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 (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);
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#ifdef __cplusplus +#include <forward_list> +#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 = 2, N = 50000000, S = 0x3ffc, R = 4}; +uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff; + +static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } + +#define i_val size_t +#define i_tag x +#include <stc/clist.h> + +#ifdef __cplusplus +Sample test_std_forward_list() { + typedef std::forward_list<size_t> container; + Sample s = {"std,forward_list"}; + { + s.test[INSERT].t1 = clock(); + container con; + csrandom(seed); + c_forrange (N/2) con.push_front(crandom() & mask1); + c_forrange (N/2) con.push_front(crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = 0; + s.test[ERASE].t1 = clock(); + c_forrange (N) con.pop_front(); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = 0; + }{ + container con; + csrandom(seed); + c_forrange (N) con.push_front(crandom() & 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(), crandom() & mask2)) != con.end()) sum += *it; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) for (auto i: con) sum += i; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} +#else +Sample test_std_forward_list() { Sample s = {"std-forward_list"}; return s;} +#endif + + +Sample test_stc_forward_list() { + typedef clist_x container; + Sample s = {"STC,forward_list"}; + { + s.test[INSERT].t1 = clock(); + container con = clist_x_init(); + csrandom(seed); + c_forrange (N/2) clist_x_push_front(&con, crandom() & mask1); + c_forrange (N/2) clist_x_push_back(&con, crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = 0; + s.test[ERASE].t1 = clock(); + c_forrange (N) clist_x_pop_front(&con); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = 0; + clist_x_drop(&con); + }{ + csrandom(seed); + container con = clist_x_init(); + c_forrange (N) clist_x_push_front(&con, crandom() & mask2); + s.test[FIND].t1 = clock(); + size_t sum = 0; + //clist_x_iter it, end = clist_x_end(&con); + //c_forrange (S) if ((it = clist_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_foreach (i, clist_x, con) sum += *i.ref; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + clist_x_drop(&con); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} + +int main(int argc, char* argv[]) +{ + Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; + c_forrange (i, int, SAMPLES) { + std_s[i] = test_std_forward_list(); + stc_s[i] = test_stc_forward_list(); + if (i > 0) c_forrange (j, int, N_TESTS) { + if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; + if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; + 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 (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); }
\ No newline at end of file diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index 1021ab1c..781ad720 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -1,134 +1,134 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#ifdef __cplusplus
-#include <unordered_map>
-#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 = 2, N = 8000000, R = 4};
-uint64_t seed = 1, mask1 = 0xffffffff;
-
-static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-
-#define i_key uint64_t
-#define i_val uint64_t
-#define i_tag x
-#include <stc/cmap.h>
-
-#ifdef __cplusplus
-Sample test_std_unordered_map() {
- typedef std::unordered_map<uint64_t, uint64_t> container;
- Sample s = {"std,unordered_map"};
- {
- csrandom(seed);
- s.test[INSERT].t1 = clock();
- container con;
- c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
- c_forrange (i, N/2) con.emplace(i, i);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = con.size();
- csrandom(seed);
- s.test[ERASE].t1 = clock();
- c_forrange (N) con.erase(crandom() & mask1);
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = con.size();
- }{
- container con;
- csrandom(seed);
- c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
- c_forrange (i, N/2) con.emplace(i, i);
- csrandom(seed);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- container::iterator it;
- c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) for (auto i: con) sum += i.second;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-#else
-Sample test_std_unordered_map() { Sample s = {"std-unordered_map"}; return s;}
-#endif
-
-
-Sample test_stc_unordered_map() {
- typedef cmap_x container;
- Sample s = {"STC,unordered_map"};
- {
- csrandom(seed);
- s.test[INSERT].t1 = clock();
- container con = cmap_x_init();
- c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
- c_forrange (i, N/2) cmap_x_insert(&con, i, i);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = cmap_x_size(con);
- csrandom(seed);
- s.test[ERASE].t1 = clock();
- c_forrange (N) cmap_x_erase(&con, crandom() & mask1);
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = cmap_x_size(con);
- cmap_x_drop(&con);
- }{
- container con = cmap_x_init();
- csrandom(seed);
- c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i);
- c_forrange (i, N/2) cmap_x_insert(&con, i, i);
- csrandom(seed);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- const cmap_x_value* val;
- c_forrange (N)
- if ((val = cmap_x_get(&con, crandom() & mask1)))
- sum += val->second;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_foreach (i, cmap_x, con) sum += i.ref->second;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- cmap_x_drop(&con);
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-
-int main(int argc, char* argv[])
-{
- Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (i, int, SAMPLES) {
- std_s[i] = test_std_unordered_map();
- stc_s[i] = test_stc_unordered_map();
- if (i > 0) c_forrange (j, int, N_TESTS) {
- if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
- if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
- 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 (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);
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#ifdef __cplusplus +#include <unordered_map> +#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 = 2, N = 8000000, R = 4}; +uint64_t seed = 1, mask1 = 0xffffffff; + +static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } + +#define i_key uint64_t +#define i_val uint64_t +#define i_tag x +#include <stc/cmap.h> + +#ifdef __cplusplus +Sample test_std_unordered_map() { + typedef std::unordered_map<uint64_t, uint64_t> container; + Sample s = {"std,unordered_map"}; + { + csrandom(seed); + s.test[INSERT].t1 = clock(); + container con; + c_forrange (i, N/2) con.emplace(crandom() & mask1, i); + c_forrange (i, N/2) con.emplace(i, i); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = con.size(); + csrandom(seed); + s.test[ERASE].t1 = clock(); + c_forrange (N) con.erase(crandom() & mask1); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = con.size(); + }{ + container con; + csrandom(seed); + c_forrange (i, N/2) con.emplace(crandom() & mask1, i); + c_forrange (i, N/2) con.emplace(i, i); + csrandom(seed); + s.test[FIND].t1 = clock(); + size_t sum = 0; + container::iterator it; + c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) for (auto i: con) sum += i.second; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} +#else +Sample test_std_unordered_map() { Sample s = {"std-unordered_map"}; return s;} +#endif + + +Sample test_stc_unordered_map() { + typedef cmap_x container; + Sample s = {"STC,unordered_map"}; + { + csrandom(seed); + s.test[INSERT].t1 = clock(); + container con = cmap_x_init(); + c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i); + c_forrange (i, N/2) cmap_x_insert(&con, i, i); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = cmap_x_size(con); + csrandom(seed); + s.test[ERASE].t1 = clock(); + c_forrange (N) cmap_x_erase(&con, crandom() & mask1); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = cmap_x_size(con); + cmap_x_drop(&con); + }{ + container con = cmap_x_init(); + csrandom(seed); + c_forrange (i, N/2) cmap_x_insert(&con, crandom() & mask1, i); + c_forrange (i, N/2) cmap_x_insert(&con, i, i); + csrandom(seed); + s.test[FIND].t1 = clock(); + size_t sum = 0; + const cmap_x_value* val; + c_forrange (N) + if ((val = cmap_x_get(&con, crandom() & mask1))) + sum += val->second; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_foreach (i, cmap_x, con) sum += i.ref->second; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + cmap_x_drop(&con); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} + +int main(int argc, char* argv[]) +{ + Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; + c_forrange (i, int, SAMPLES) { + std_s[i] = test_std_unordered_map(); + stc_s[i] = test_stc_unordered_map(); + if (i > 0) c_forrange (j, int, N_TESTS) { + if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; + if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; + 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 (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); }
\ No newline at end of file diff --git a/benchmarks/plotbench/cpque_benchmark.cpp b/benchmarks/plotbench/cpque_benchmark.cpp index b38bed1a..afa9c07e 100644 --- a/benchmarks/plotbench/cpque_benchmark.cpp +++ b/benchmarks/plotbench/cpque_benchmark.cpp @@ -1,71 +1,71 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#define i_val float
-#define i_cmp -c_default_cmp
-#define i_tag f
-#include <stc/cpque.h>
-
-#include <queue>
-
-static const uint32_t seed = 1234;
-
-void std_test()
-{
- stc64_t rng;
- int N = 10000000, M = 10;
-
- std::priority_queue<float, std::vector<float>, std::greater<float>> pq;
- rng = stc64_new(seed);
- clock_t start = clock();
- c_forrange (i, N)
- pq.push((float) stc64_randf(&rng)*100000);
-
- printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
- printf("%g ", pq.top());
-
- start = clock();
- c_forrange (i, N) {
- pq.pop();
- }
-
- printf("\npopped PQ: %f secs\n\n", (clock() - start) / (float) CLOCKS_PER_SEC);
-}
-
-
-void stc_test()
-{
- stc64_t rng;
- int N = 10000000, M = 10;
-
- c_auto (cpque_f, pq)
- {
- rng = stc64_new(seed);
- clock_t start = clock();
- c_forrange (i, N)
- cpque_f_push(&pq, (float) stc64_randf(&rng)*100000);
-
- printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
- printf("%g ", *cpque_f_top(&pq));
-
- c_forrange (i, int, M) {
- cpque_f_pop(&pq);
- }
-
- start = clock();
- c_forrange (i, int, M, N)
- cpque_f_pop(&pq);
- printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
- }
-}
-
-
-int main()
-{
- puts("STD P.QUEUE:");
- std_test();
- puts("\nSTC P.QUEUE:");
- stc_test();
-}
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#define i_val float +#define i_cmp -c_default_cmp +#define i_tag f +#include <stc/cpque.h> + +#include <queue> + +static const uint32_t seed = 1234; + +void std_test() +{ + stc64_t rng; + int N = 10000000, M = 10; + + std::priority_queue<float, std::vector<float>, std::greater<float>> pq; + rng = stc64_new(seed); + clock_t start = clock(); + c_forrange (i, N) + pq.push((float) stc64_randf(&rng)*100000); + + printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("%g ", pq.top()); + + start = clock(); + c_forrange (i, N) { + pq.pop(); + } + + printf("\npopped PQ: %f secs\n\n", (clock() - start) / (float) CLOCKS_PER_SEC); +} + + +void stc_test() +{ + stc64_t rng; + int N = 10000000, M = 10; + + c_auto (cpque_f, pq) + { + rng = stc64_new(seed); + clock_t start = clock(); + c_forrange (i, N) + cpque_f_push(&pq, (float) stc64_randf(&rng)*100000); + + printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("%g ", *cpque_f_top(&pq)); + + c_forrange (i, int, M) { + cpque_f_pop(&pq); + } + + start = clock(); + c_forrange (i, int, M, N) + cpque_f_pop(&pq); + printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + } +} + + +int main() +{ + puts("STD P.QUEUE:"); + std_test(); + puts("\nSTC P.QUEUE:"); + stc_test(); +} diff --git a/benchmarks/plotbench/csmap_benchmark.cpp b/benchmarks/plotbench/csmap_benchmark.cpp index 778d6894..3fb8a0a4 100644 --- a/benchmarks/plotbench/csmap_benchmark.cpp +++ b/benchmarks/plotbench/csmap_benchmark.cpp @@ -1,135 +1,135 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#ifdef __cplusplus
-#include <map>
-#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 = 2, N = 4000000, R = 4};
-uint64_t seed = 1, mask1 = 0xfffffff;
-
-static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-
-#define i_key size_t
-#define i_val size_t
-#define i_tag x
-#include <stc/csmap.h>
-
-#ifdef __cplusplus
-Sample test_std_map() {
- typedef std::map<size_t, size_t> container;
- Sample s = {"std,map"};
- {
- csrandom(seed);
- s.test[INSERT].t1 = clock();
- container con;
- c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
- c_forrange (i, N/2) con.emplace(i, i);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = con.size();
- csrandom(seed);
- s.test[ERASE].t1 = clock();
- c_forrange (N) con.erase(crandom() & mask1);
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = con.size();
- }{
- container con;
- csrandom(seed);
- c_forrange (i, N/2) con.emplace(crandom() & mask1, i);
- c_forrange (i, N/2) con.emplace(i, i);
- csrandom(seed);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- container::iterator it;
- c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) for (auto i: con) sum += i.second;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-#else
-Sample test_std_map() { Sample s = {"std-map"}; return s;}
-#endif
-
-
-
-Sample test_stc_map() {
- typedef csmap_x container;
- Sample s = {"STC,map"};
- {
- csrandom(seed);
- s.test[INSERT].t1 = clock();
- container con = csmap_x_init();
- c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
- c_forrange (i, N/2) csmap_x_insert(&con, i, i);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = csmap_x_size(con);
- csrandom(seed);
- s.test[ERASE].t1 = clock();
- c_forrange (N) csmap_x_erase(&con, crandom() & mask1);
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = csmap_x_size(con);
- csmap_x_drop(&con);
- }{
- container con = csmap_x_init();
- csrandom(seed);
- c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i);
- c_forrange (i, N/2) csmap_x_insert(&con, i, i);
- csrandom(seed);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- const csmap_x_value* val;
- c_forrange (N)
- if ((val = csmap_x_get(&con, crandom() & mask1)))
- sum += val->second;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_foreach (i, csmap_x, con) sum += i.ref->second;
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- csmap_x_drop(&con);
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-
-int main(int argc, char* argv[])
-{
- Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (i, int, SAMPLES) {
- std_s[i] = test_std_map();
- stc_s[i] = test_stc_map();
- if (i > 0) c_forrange (j, int, N_TESTS) {
- if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
- if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
- 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 (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);
-}
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#ifdef __cplusplus +#include <map> +#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 = 2, N = 4000000, R = 4}; +uint64_t seed = 1, mask1 = 0xfffffff; + +static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } + +#define i_key size_t +#define i_val size_t +#define i_tag x +#include <stc/csmap.h> + +#ifdef __cplusplus +Sample test_std_map() { + typedef std::map<size_t, size_t> container; + Sample s = {"std,map"}; + { + csrandom(seed); + s.test[INSERT].t1 = clock(); + container con; + c_forrange (i, N/2) con.emplace(crandom() & mask1, i); + c_forrange (i, N/2) con.emplace(i, i); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = con.size(); + csrandom(seed); + s.test[ERASE].t1 = clock(); + c_forrange (N) con.erase(crandom() & mask1); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = con.size(); + }{ + container con; + csrandom(seed); + c_forrange (i, N/2) con.emplace(crandom() & mask1, i); + c_forrange (i, N/2) con.emplace(i, i); + csrandom(seed); + s.test[FIND].t1 = clock(); + size_t sum = 0; + container::iterator it; + c_forrange (N) if ((it = con.find(crandom() & mask1)) != con.end()) sum += it->second; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) for (auto i: con) sum += i.second; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} +#else +Sample test_std_map() { Sample s = {"std-map"}; return s;} +#endif + + + +Sample test_stc_map() { + typedef csmap_x container; + Sample s = {"STC,map"}; + { + csrandom(seed); + s.test[INSERT].t1 = clock(); + container con = csmap_x_init(); + c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i); + c_forrange (i, N/2) csmap_x_insert(&con, i, i); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = csmap_x_size(con); + csrandom(seed); + s.test[ERASE].t1 = clock(); + c_forrange (N) csmap_x_erase(&con, crandom() & mask1); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = csmap_x_size(con); + csmap_x_drop(&con); + }{ + container con = csmap_x_init(); + csrandom(seed); + c_forrange (i, N/2) csmap_x_insert(&con, crandom() & mask1, i); + c_forrange (i, N/2) csmap_x_insert(&con, i, i); + csrandom(seed); + s.test[FIND].t1 = clock(); + size_t sum = 0; + const csmap_x_value* val; + c_forrange (N) + if ((val = csmap_x_get(&con, crandom() & mask1))) + sum += val->second; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_foreach (i, csmap_x, con) sum += i.ref->second; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + csmap_x_drop(&con); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} + +int main(int argc, char* argv[]) +{ + Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1]; + c_forrange (i, int, SAMPLES) { + std_s[i] = test_std_map(); + stc_s[i] = test_stc_map(); + if (i > 0) c_forrange (j, int, N_TESTS) { + if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; + if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; + 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 (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); +} diff --git a/benchmarks/plotbench/cvec_benchmark.cpp b/benchmarks/plotbench/cvec_benchmark.cpp index c23b689a..9ba95f31 100644 --- a/benchmarks/plotbench/cvec_benchmark.cpp +++ b/benchmarks/plotbench/cvec_benchmark.cpp @@ -1,126 +1,126 @@ -#include <stdio.h>
-#include <time.h>
-#define i_static
-#include <stc/crandom.h>
-
-#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 = 2, N = 150000000, S = 0x3ffc, R = 4};
-uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff;
-
-static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-
-#define i_val size_t
-#define i_tag x
-#include <stc/cvec.h>
-
-#ifdef __cplusplus
-Sample test_std_vector() {
- typedef std::vector<size_t> container;
- Sample s = {"std,vector"};
- {
- s.test[INSERT].t1 = clock();
- container con;
- csrandom(seed);
- c_forrange (N) con.push_back(crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = con.size();
- s.test[ERASE].t1 = clock();
- c_forrange (N) con.pop_back();
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = con.size();
- }{
- container con;
- csrandom(seed);
- c_forrange (N) con.push_back(crandom() & 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(), crandom() & mask2)) != con.end()) sum += *it;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con[i];
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-#else
-Sample test_std_vector() { Sample s = {"std-vector"}; return s;}
-#endif
-
-
-
-Sample test_stc_vector() {
- typedef cvec_x container;
- Sample s = {"STC,vector"};
- {
- s.test[INSERT].t1 = clock();
- container con = cvec_x_init();
- csrandom(seed);
- c_forrange (N) cvec_x_push_back(&con, crandom() & mask1);
- s.test[INSERT].t2 = clock();
- s.test[INSERT].sum = cvec_x_size(con);
- s.test[ERASE].t1 = clock();
- c_forrange (N) { cvec_x_pop_back(&con); }
- s.test[ERASE].t2 = clock();
- s.test[ERASE].sum = cvec_x_size(con);
- cvec_x_drop(&con);
- }{
- csrandom(seed);
- container con = cvec_x_init();
- c_forrange (N) cvec_x_push_back(&con, crandom() & mask2);
- s.test[FIND].t1 = clock();
- size_t sum = 0;
- //cvec_x_iter it, end = cvec_x_end(&con);
- //c_forrange (S) if ((it = cvec_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref;
- s.test[FIND].t2 = clock();
- s.test[FIND].sum = sum;
- s.test[ITER].t1 = clock();
- sum = 0;
- c_forrange (R) c_forrange (i, N) sum += con.data[i];
- s.test[ITER].t2 = clock();
- s.test[ITER].sum = sum;
- s.test[DESTRUCT].t1 = clock();
- cvec_x_drop(&con);
- }
- s.test[DESTRUCT].t2 = clock();
- s.test[DESTRUCT].sum = 0;
- return s;
-}
-
-int main(int argc, char* argv[])
-{
- Sample std_s[SAMPLES + 1] = {0}, stc_s[SAMPLES + 1] = {0};
- c_forrange (i, int, SAMPLES) {
- std_s[i] = test_std_vector();
- stc_s[i] = test_stc_vector();
- if (i > 0) c_forrange (j, int, N_TESTS) {
- if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
- if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
- 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 (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);
-}
+#include <stdio.h> +#include <time.h> +#define i_static +#include <stc/crandom.h> + +#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 = 2, N = 150000000, S = 0x3ffc, R = 4}; +uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff; + +static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } + +#define i_val size_t +#define i_tag x +#include <stc/cvec.h> + +#ifdef __cplusplus +Sample test_std_vector() { + typedef std::vector<size_t> container; + Sample s = {"std,vector"}; + { + s.test[INSERT].t1 = clock(); + container con; + csrandom(seed); + c_forrange (N) con.push_back(crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = con.size(); + s.test[ERASE].t1 = clock(); + c_forrange (N) con.pop_back(); + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = con.size(); + }{ + container con; + csrandom(seed); + c_forrange (N) con.push_back(crandom() & 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(), crandom() & mask2)) != con.end()) sum += *it; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_forrange (i, N) sum += con[i]; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} +#else +Sample test_std_vector() { Sample s = {"std-vector"}; return s;} +#endif + + + +Sample test_stc_vector() { + typedef cvec_x container; + Sample s = {"STC,vector"}; + { + s.test[INSERT].t1 = clock(); + container con = cvec_x_init(); + csrandom(seed); + c_forrange (N) cvec_x_push_back(&con, crandom() & mask1); + s.test[INSERT].t2 = clock(); + s.test[INSERT].sum = cvec_x_size(con); + s.test[ERASE].t1 = clock(); + c_forrange (N) { cvec_x_pop_back(&con); } + s.test[ERASE].t2 = clock(); + s.test[ERASE].sum = cvec_x_size(con); + cvec_x_drop(&con); + }{ + csrandom(seed); + container con = cvec_x_init(); + c_forrange (N) cvec_x_push_back(&con, crandom() & mask2); + s.test[FIND].t1 = clock(); + size_t sum = 0; + //cvec_x_iter it, end = cvec_x_end(&con); + //c_forrange (S) if ((it = cvec_x_find(&con, crandom() & mask2)).ref != end.ref) sum += *it.ref; + s.test[FIND].t2 = clock(); + s.test[FIND].sum = sum; + s.test[ITER].t1 = clock(); + sum = 0; + c_forrange (R) c_forrange (i, N) sum += con.data[i]; + s.test[ITER].t2 = clock(); + s.test[ITER].sum = sum; + s.test[DESTRUCT].t1 = clock(); + cvec_x_drop(&con); + } + s.test[DESTRUCT].t2 = clock(); + s.test[DESTRUCT].sum = 0; + return s; +} + +int main(int argc, char* argv[]) +{ + Sample std_s[SAMPLES + 1] = {0}, stc_s[SAMPLES + 1] = {0}; + c_forrange (i, int, SAMPLES) { + std_s[i] = test_std_vector(); + stc_s[i] = test_stc_vector(); + if (i > 0) c_forrange (j, int, N_TESTS) { + if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j]; + if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j]; + 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 (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); +} |
