diff options
| author | Tyge Løvset <[email protected]> | 2022-01-13 14:49:13 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-01-13 14:49:13 +0100 |
| commit | 4a421181052483cef097746fcaaa9027aaf99a7d (patch) | |
| tree | b6a019d7f1cb9cb511e243774251c193c7d23f67 /benchmarks/plotbench/cpque_benchmark.cpp | |
| parent | ff08e1bb0469750aff5367ae2534278a739bb5d3 (diff) | |
| download | STC-modified-4a421181052483cef097746fcaaa9027aaf99a7d.tar.gz STC-modified-4a421181052483cef097746fcaaa9027aaf99a7d.zip | |
Fixed missing i_eq default setting in template.h, carc and cbox. cstr_substr_utf8 added.
Diffstat (limited to 'benchmarks/plotbench/cpque_benchmark.cpp')
| -rw-r--r-- | benchmarks/plotbench/cpque_benchmark.cpp | 63 |
1 files changed, 43 insertions, 20 deletions
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 <stc/cpque.h>
-int main()
+#include <queue>
+
+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<float, std::vector<float>, std::greater<float>> 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();
}
|
