From a0a290645828c88597efce80f6b0f5a958cefa89 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 30 Mar 2023 17:59:08 +0200 Subject: Added crand.h - Alternative API to crandom.h, which will be deprecated. --- misc/benchmarks/plotbench/cpque_benchmark.cpp | 32 ++++++++++++--------------- 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'misc/benchmarks/plotbench/cpque_benchmark.cpp') diff --git a/misc/benchmarks/plotbench/cpque_benchmark.cpp b/misc/benchmarks/plotbench/cpque_benchmark.cpp index a729c09f..da092b7f 100644 --- a/misc/benchmarks/plotbench/cpque_benchmark.cpp +++ b/misc/benchmarks/plotbench/cpque_benchmark.cpp @@ -1,7 +1,7 @@ #include #include #define i_static -#include +#include #define i_val float #define i_cmp -c_default_cmp @@ -11,19 +11,17 @@ #include static const uint32_t seed = 1234; +static const int N = 10000000; void std_test() { - stc64_t rng; - int N = 10000000; - std::priority_queue, std::greater> pq; - rng = stc64_new(seed); + csrand(seed); clock_t start = clock(); c_forrange (i, N) - pq.push((float) stc64_randf(&rng)*100000); + pq.push((float) crandf()*100000.0); - printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("Built priority queue: %f secs\n", (float)(clock() - start)/(float)CLOCKS_PER_SEC); printf("%g ", pq.top()); start = clock(); @@ -31,32 +29,30 @@ void std_test() pq.pop(); } - printf("\npopped PQ: %f secs\n\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("\npopped PQ: %f secs\n\n", (float)(clock() - start)/(float)CLOCKS_PER_SEC); } void stc_test() { - stc64_t rng; - int N = 10000000, M = 10; + int N = 10000000; c_auto (cpque_f, pq) { - rng = stc64_new(seed); + csrand(seed); clock_t start = clock(); - c_forrange (i, N) - cpque_f_push(&pq, (float) stc64_randf(&rng)*100000); + c_forrange (i, N) { + cpque_f_push(&pq, (float) crandf()*100000); + } - printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("Built priority queue: %f secs\n", (float)(clock() - start)/(float)CLOCKS_PER_SEC); printf("%g ", *cpque_f_top(&pq)); - c_forrange (i, M) { + start = clock(); + c_forrange (i, N) { cpque_f_pop(&pq); } - start = clock(); - c_forrange (i, M, N) - cpque_f_pop(&pq); printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); } } -- cgit v1.2.3