From 4a421181052483cef097746fcaaa9027aaf99a7d Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 13 Jan 2022 14:49:13 +0100 Subject: Fixed missing i_eq default setting in template.h, carc and cbox. cstr_substr_utf8 added. --- benchmarks/plotbench/cpque_benchmark.cpp | 63 ++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'benchmarks/plotbench') diff --git a/benchmarks/plotbench/cpque_benchmark.cpp b/benchmarks/plotbench/cpque_benchmark.cpp index 2b6d3748..84bbe468 100644 --- a/benchmarks/plotbench/cpque_benchmark.cpp +++ b/benchmarks/plotbench/cpque_benchmark.cpp @@ -7,41 +7,64 @@ #define i_tag f #include -int main() +#include + +static const uint32_t seed = 1234; + +void std_test() { - uint32_t seed = time(NULL); stc64_t rng; int N = 10000000, M = 10; - cpque_f pq = cpque_f_with_size(N, 0.0f); + std::priority_queue, std::greater> pq; rng = stc64_init(seed); clock_t start = clock(); c_forrange (i, N) - pq.data[i] = (float) stc64_randf(&rng)*100000; + pq.push((float) stc64_randf(&rng)*100000); - cpque_f_make_heap(&pq); printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("%g ", pq.top()); - c_forrange (i, int, M) { - printf("%g ", *cpque_f_top(&pq)); - cpque_f_pop(&pq); + start = clock(); + c_forrange (i, N) { + pq.pop(); } - start = clock(); - c_forrange (i, int, M, N) - cpque_f_pop(&pq); - printf("\n\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("\npopped PQ: %f secs\n\n", (clock() - start) / (float) CLOCKS_PER_SEC); +} - start = clock(); - c_forrange (i, int, N) - cpque_f_push(&pq, (float) stc64_randf(&rng)*100000); - printf("pushed PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); - c_forrange (i, int, M) { +void stc_test() +{ + stc64_t rng; + int N = 10000000, M = 10; + + c_auto (cpque_f, pq) + { + rng = stc64_init(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)); - cpque_f_pop(&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); } - puts(""); +} + - cpque_f_drop(&pq); +int main() +{ + puts("STD P.QUEUE:"); + std_test(); + puts("\nSTC P.QUEUE:"); + stc_test(); } -- cgit v1.2.3