summaryrefslogtreecommitdiffhomepage
path: root/benchmarks/cpque_benchmark.cpp
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-12-21 14:28:56 +0100
committerTyge Løvset <[email protected]>2020-12-21 14:28:56 +0100
commita9ce3df5c59515c12d4fcdf3b7ad43cefdf122b6 (patch)
treefc4dd05322c03608dd3b756921380558965d1166 /benchmarks/cpque_benchmark.cpp
parenta6657b9f4b22afbdb1c98ce462d74665856a6f05 (diff)
downloadSTC-modified-a9ce3df5c59515c12d4fcdf3b7ad43cefdf122b6.tar.gz
STC-modified-a9ce3df5c59515c12d4fcdf3b7ad43cefdf122b6.zip
Added some benchmarks. Fix typo in cdeq.h
Diffstat (limited to 'benchmarks/cpque_benchmark.cpp')
-rw-r--r--benchmarks/cpque_benchmark.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/benchmarks/cpque_benchmark.cpp b/benchmarks/cpque_benchmark.cpp
new file mode 100644
index 00000000..625bb056
--- /dev/null
+++ b/benchmarks/cpque_benchmark.cpp
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <time.h>
+#include <stc/crand.h>
+#include <stc/cvec.h>
+#include <stc/cpque.h>
+
+using_cvec(f, float);
+using_cpque(f, cvec_f, >);
+
+int main()
+{
+ uint32_t seed = time(NULL);
+ crand_t rng;
+ int N = 10000000, M = 10;
+
+ cpque_f pq = cpque_f_init();
+
+ rng = crand_init(seed);
+ clock_t start = clock();
+ c_forrange (i, int, N)
+ cvec_f_push_back(&pq, (float) crand_nextf(&rng)*100000);
+
+ cpque_f_make_heap(&pq);
+ printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
+
+ c_forrange (i, int, M) {
+ printf("%g ", *cpque_f_top(&pq));
+ cpque_f_pop(&pq);
+ }
+
+ 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);
+
+ start = clock();
+ c_forrange (i, int, N)
+ cpque_f_push(&pq, (float) crand_nextf(&rng)*100000);
+ printf("pushed PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
+
+ c_forrange (i, int, M) {
+ printf("%g ", *cpque_f_top(&pq));
+ cpque_f_pop(&pq);
+ }
+ puts("");
+
+ cpque_f_del(&pq);
+}