summaryrefslogtreecommitdiffhomepage
path: root/benchmarks
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-06-01 16:28:07 +0200
committerTyge Løvset <[email protected]>2022-06-01 16:28:07 +0200
commitde629774cb912aa3d563f24d99258142713c3fcd (patch)
treec37e2851d6cb049bc0863a59b6ecf5945fb88619 /benchmarks
parent7fb43a24a17da787dd809114ca26c1231b058493 (diff)
downloadSTC-modified-de629774cb912aa3d563f24d99258142713c3fcd.tar.gz
STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.zip
Converted all files with DOS line endings to LINUX.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/misc/prng_bench.cpp412
-rw-r--r--benchmarks/misc/rust_cmap.c120
-rw-r--r--benchmarks/picobench/picobench_cmap.cpp604
-rw-r--r--benchmarks/picobench/picobench_csmap.cpp644
-rw-r--r--benchmarks/plotbench/cdeq_benchmark.cpp260
-rw-r--r--benchmarks/plotbench/clist_benchmark.cpp252
-rw-r--r--benchmarks/plotbench/cmap_benchmark.cpp266
-rw-r--r--benchmarks/plotbench/cpque_benchmark.cpp142
-rw-r--r--benchmarks/plotbench/csmap_benchmark.cpp270
-rw-r--r--benchmarks/plotbench/cvec_benchmark.cpp252
10 files changed, 1611 insertions, 1611 deletions
diff --git a/benchmarks/misc/prng_bench.cpp b/benchmarks/misc/prng_bench.cpp
index 9d840316..2bb25429 100644
--- a/benchmarks/misc/prng_bench.cpp
+++ b/benchmarks/misc/prng_bench.cpp
@@ -1,206 +1,206 @@
-#include <cstdint>
-#include <iostream>
-#include <ctime>
-#include <random>
-#include <stc/crandom.h>
-
-static inline uint64_t rotl64(const uint64_t x, const int k)
- { return (x << k) | (x >> (64 - k)); }
-
-static uint64_t splitmix64_x = 87213627321ull; /* The state can be seeded with any value. */
-
-uint64_t splitmix64(void) {
- uint64_t z = (splitmix64_x += 0x9e3779b97f4a7c15);
- z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
- z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
- return z ^ (z >> 31);
-}
-
-static void init_state(uint64_t *rng, uint64_t seed) {
- splitmix64_x = seed;
- for (int i=0; i<4; ++i) rng[i] = splitmix64();
-}
-
-/* romu_trio */
-
-uint64_t romu_trio(uint64_t s[3]) {
- uint64_t xp = s[0], yp = s[1], zp = s[2];
- s[0] = 15241094284759029579u * zp;
- s[1] = yp - xp; s[1] = rotl64(s[1], 12);
- s[2] = zp - yp; s[2] = rotl64(s[2], 44);
- return xp;
-}
-
-/* sfc64 */
-
-static inline uint64_t sfc64(uint64_t s[4]) {
- uint64_t result = s[0] + s[1] + s[3]++;
- s[0] = s[1] ^ (s[1] >> 11);
- s[1] = s[2] + (s[2] << 3);
- s[2] = rotl64(s[2], 24) + result;
- return result;
-}
-
-uint32_t sfc32(uint32_t s[4]) {
- uint32_t t = s[0] + s[1] + s[3]++;
- s[0] = s[1] ^ (s[1] >> 9);
- s[1] = s[2] + (s[2] << 3);
- s[2] = (s[2] << 21) | (s[2] >> 11) + t;
- return t;
-}
-
-uint32_t stc32(uint32_t s[5]) {
- uint32_t t = (s[0] ^ (s[3] += s[4])) + s[1];
- s[0] = s[1] ^ (s[1] >> 9);
- s[1] = s[2] + (s[2] << 3);
- s[2] = (s[2] << 21) | (s[2] >> 11) + t;
- return t;
-}
-
-/* xoshiro128+ */
-
-uint64_t xoroshiro128plus(uint64_t s[2]) {
- const uint64_t s0 = s[0];
- uint64_t s1 = s[1];
- const uint64_t result = s0 + s1;
-
- s1 ^= s0;
- s[0] = rotl64(s0, 24) ^ s1 ^ (s1 << 16); // a, b
- s[1] = rotl64(s1, 37); // c
-
- return result;
-}
-
-
-/* xoshiro256** */
-
-static inline uint64_t xoshiro256starstar(uint64_t s[4]) {
- const uint64_t result = rotl64(s[1] * 5, 7) * 9;
- const uint64_t t = s[1] << 17;
- s[2] ^= s[0];
- s[3] ^= s[1];
- s[1] ^= s[2];
- s[0] ^= s[3];
- s[2] ^= t;
- s[3] = rotl64(s[3], 45);
- return result;
-}
-
-// wyrand - 2020-12-07
-static inline void _wymum(uint64_t *A, uint64_t *B){
-#if defined(__SIZEOF_INT128__)
- __uint128_t r = *A; r *= *B;
- *A = (uint64_t) r; *B = (uint64_t ) (r >> 64);
-#elif defined(_MSC_VER) && defined(_M_X64)
- *A = _umul128(*A, *B, B);
-#else
- uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B, hi, lo;
- uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t<rl;
- lo=t+(rm1<<32); c+=lo<t; hi=rh+(rm0>>32)+(rm1>>32)+c;
- *A=lo; *B=hi;
-#endif
-}
-static inline uint64_t _wymix(uint64_t A, uint64_t B){
- _wymum(&A,&B); return A^B;
-}
-static inline uint64_t wyrand64(uint64_t *seed){
- static const uint64_t _wyp[] = {0xa0761d6478bd642full, 0xe7037ed1a0b428dbull};
- *seed+=_wyp[0]; return _wymix(*seed,*seed^_wyp[1]);
-}
-
-
-using namespace std;
-
-int main(void)
-{
- enum {N = 2000000000};
- uint16_t* recipient = new uint16_t[N];
- static stc64_t rng;
- init_state(rng.state, 12345123);
- std::mt19937 mt(12345123);
-
- cout << "WARMUP" << endl;
- for (size_t i = 0; i < N; i++)
- recipient[i] = wyrand64(rng.state);
-
- clock_t beg, end;
- for (size_t ti = 0; ti < 2; ti++) {
- init_state(rng.state, 12345123);
- cout << endl << "ROUND " << ti+1 << " ---------" << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = romu_trio(rng.state);
- end = clock();
- cout << "romu_trio:\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = wyrand64(rng.state);
- end = clock();
- cout << "wyrand64:\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = sfc32((uint32_t *)rng.state);
- end = clock();
- cout << "sfc32:\t\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = stc32((uint32_t *)rng.state);
- end = clock();
- cout << "stc32:\t\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = sfc64(rng.state);
- end = clock();
- cout << "sfc64:\t\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = stc64_rand(&rng);
- end = clock();
- cout << "stc64:\t\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = xoroshiro128plus(rng.state);
- end = clock();
- cout << "xoroshiro128+:\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = xoshiro256starstar(rng.state);
- end = clock();
- cout << "xoshiro256**:\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
-
- beg = clock();
- for (size_t i = 0; i < N; i++)
- recipient[i] = mt();
- end = clock();
- cout << "std::mt19937:\t"
- << (float(end - beg) / CLOCKS_PER_SEC)
- << "s: " << recipient[312] << endl;
- }
- delete[] recipient;
- return 0;
-}
+#include <cstdint>
+#include <iostream>
+#include <ctime>
+#include <random>
+#include <stc/crandom.h>
+
+static inline uint64_t rotl64(const uint64_t x, const int k)
+ { return (x << k) | (x >> (64 - k)); }
+
+static uint64_t splitmix64_x = 87213627321ull; /* The state can be seeded with any value. */
+
+uint64_t splitmix64(void) {
+ uint64_t z = (splitmix64_x += 0x9e3779b97f4a7c15);
+ z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
+ z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
+ return z ^ (z >> 31);
+}
+
+static void init_state(uint64_t *rng, uint64_t seed) {
+ splitmix64_x = seed;
+ for (int i=0; i<4; ++i) rng[i] = splitmix64();
+}
+
+/* romu_trio */
+
+uint64_t romu_trio(uint64_t s[3]) {
+ uint64_t xp = s[0], yp = s[1], zp = s[2];
+ s[0] = 15241094284759029579u * zp;
+ s[1] = yp - xp; s[1] = rotl64(s[1], 12);
+ s[2] = zp - yp; s[2] = rotl64(s[2], 44);
+ return xp;
+}
+
+/* sfc64 */
+
+static inline uint64_t sfc64(uint64_t s[4]) {
+ uint64_t result = s[0] + s[1] + s[3]++;
+ s[0] = s[1] ^ (s[1] >> 11);
+ s[1] = s[2] + (s[2] << 3);
+ s[2] = rotl64(s[2], 24) + result;
+ return result;
+}
+
+uint32_t sfc32(uint32_t s[4]) {
+ uint32_t t = s[0] + s[1] + s[3]++;
+ s[0] = s[1] ^ (s[1] >> 9);
+ s[1] = s[2] + (s[2] << 3);
+ s[2] = (s[2] << 21) | (s[2] >> 11) + t;
+ return t;
+}
+
+uint32_t stc32(uint32_t s[5]) {
+ uint32_t t = (s[0] ^ (s[3] += s[4])) + s[1];
+ s[0] = s[1] ^ (s[1] >> 9);
+ s[1] = s[2] + (s[2] << 3);
+ s[2] = (s[2] << 21) | (s[2] >> 11) + t;
+ return t;
+}
+
+/* xoshiro128+ */
+
+uint64_t xoroshiro128plus(uint64_t s[2]) {
+ const uint64_t s0 = s[0];
+ uint64_t s1 = s[1];
+ const uint64_t result = s0 + s1;
+
+ s1 ^= s0;
+ s[0] = rotl64(s0, 24) ^ s1 ^ (s1 << 16); // a, b
+ s[1] = rotl64(s1, 37); // c
+
+ return result;
+}
+
+
+/* xoshiro256** */
+
+static inline uint64_t xoshiro256starstar(uint64_t s[4]) {
+ const uint64_t result = rotl64(s[1] * 5, 7) * 9;
+ const uint64_t t = s[1] << 17;
+ s[2] ^= s[0];
+ s[3] ^= s[1];
+ s[1] ^= s[2];
+ s[0] ^= s[3];
+ s[2] ^= t;
+ s[3] = rotl64(s[3], 45);
+ return result;
+}
+
+// wyrand - 2020-12-07
+static inline void _wymum(uint64_t *A, uint64_t *B){
+#if defined(__SIZEOF_INT128__)
+ __uint128_t r = *A; r *= *B;
+ *A = (uint64_t) r; *B = (uint64_t ) (r >> 64);
+#elif defined(_MSC_VER) && defined(_M_X64)
+ *A = _umul128(*A, *B, B);
+#else
+ uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B, hi, lo;
+ uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t<rl;
+ lo=t+(rm1<<32); c+=lo<t; hi=rh+(rm0>>32)+(rm1>>32)+c;
+ *A=lo; *B=hi;
+#endif
+}
+static inline uint64_t _wymix(uint64_t A, uint64_t B){
+ _wymum(&A,&B); return A^B;
+}
+static inline uint64_t wyrand64(uint64_t *seed){
+ static const uint64_t _wyp[] = {0xa0761d6478bd642full, 0xe7037ed1a0b428dbull};
+ *seed+=_wyp[0]; return _wymix(*seed,*seed^_wyp[1]);
+}
+
+
+using namespace std;
+
+int main(void)
+{
+ enum {N = 2000000000};
+ uint16_t* recipient = new uint16_t[N];
+ static stc64_t rng;
+ init_state(rng.state, 12345123);
+ std::mt19937 mt(12345123);
+
+ cout << "WARMUP" << endl;
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = wyrand64(rng.state);
+
+ clock_t beg, end;
+ for (size_t ti = 0; ti < 2; ti++) {
+ init_state(rng.state, 12345123);
+ cout << endl << "ROUND " << ti+1 << " ---------" << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = romu_trio(rng.state);
+ end = clock();
+ cout << "romu_trio:\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = wyrand64(rng.state);
+ end = clock();
+ cout << "wyrand64:\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = sfc32((uint32_t *)rng.state);
+ end = clock();
+ cout << "sfc32:\t\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = stc32((uint32_t *)rng.state);
+ end = clock();
+ cout << "stc32:\t\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = sfc64(rng.state);
+ end = clock();
+ cout << "sfc64:\t\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = stc64_rand(&rng);
+ end = clock();
+ cout << "stc64:\t\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = xoroshiro128plus(rng.state);
+ end = clock();
+ cout << "xoroshiro128+:\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = xoshiro256starstar(rng.state);
+ end = clock();
+ cout << "xoshiro256**:\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+
+ beg = clock();
+ for (size_t i = 0; i < N; i++)
+ recipient[i] = mt();
+ end = clock();
+ cout << "std::mt19937:\t"
+ << (float(end - beg) / CLOCKS_PER_SEC)
+ << "s: " << recipient[312] << endl;
+ }
+ delete[] recipient;
+ return 0;
+}
diff --git a/benchmarks/misc/rust_cmap.c b/benchmarks/misc/rust_cmap.c
index 5a052915..1e763bde 100644
--- a/benchmarks/misc/rust_cmap.c
+++ b/benchmarks/misc/rust_cmap.c
@@ -1,61 +1,61 @@
-#include <time.h>
-#include <stdio.h>
-#define i_key uint64_t
-#define i_val uint64_t
-#define i_tag u64
-#include <stc/cmap.h>
-
-uint64_t romu_rotl(uint64_t val, uint32_t r) {
- return (val << r) | (val >> (64 - r));
-}
-
-uint64_t romu_trio(uint64_t s[3]) {
- const uint64_t xp = s[0],
- yp = s[1],
- zp = s[2];
- s[0] = 15241094284759029579u * zp;
- s[1] = yp - xp;
- s[1] = romu_rotl(s[1], 12);
- s[2] = zp - yp;
- s[2] = romu_rotl(s[2], 44);
- return xp;
-}
-
-int main()
-{
- c_auto (cmap_u64, m) {
- const size_t n = 50000000,
- mask = (1 << 25) - 1,
- ms = CLOCKS_PER_SEC/1000;
- cmap_u64_max_load_factor(&m, 0.8);
- cmap_u64_reserve(&m, n);
- printf("STC cmap n = %" PRIuMAX ", mask = 0x%" PRIxMAX "\n", n, mask);
-
- uint64_t rng[3] = {1872361123, 123879177, 87739234}, sum;
- clock_t now = clock();
- c_forrange (n) {
- uint64_t key = romu_trio(rng) & mask;
- cmap_u64_insert(&m, key, 0).ref->second += 1;
- }
- printf("insert : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
-
- now = clock();
- sum = 0;
- c_forrange (key, mask + 1) { sum += cmap_u64_contains(&m, key); }
- printf("lookup : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
-
- now = clock();
- sum = 0;
- c_foreach (i, cmap_u64, m) { sum += i.ref->second; }
- printf("iterate : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
-
- uint64_t rng2[3] = {1872361123, 123879177, 87739234};
- now = clock();
- c_forrange (n) {
- uint64_t key = romu_trio(rng2) & mask;
- cmap_u64_erase(&m, key);
- }
- printf("remove : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
- printf("press a key:\n"); getchar();
- }
+#include <time.h>
+#include <stdio.h>
+#define i_key uint64_t
+#define i_val uint64_t
+#define i_tag u64
+#include <stc/cmap.h>
+
+uint64_t romu_rotl(uint64_t val, uint32_t r) {
+ return (val << r) | (val >> (64 - r));
+}
+
+uint64_t romu_trio(uint64_t s[3]) {
+ const uint64_t xp = s[0],
+ yp = s[1],
+ zp = s[2];
+ s[0] = 15241094284759029579u * zp;
+ s[1] = yp - xp;
+ s[1] = romu_rotl(s[1], 12);
+ s[2] = zp - yp;
+ s[2] = romu_rotl(s[2], 44);
+ return xp;
+}
+
+int main()
+{
+ c_auto (cmap_u64, m) {
+ const size_t n = 50000000,
+ mask = (1 << 25) - 1,
+ ms = CLOCKS_PER_SEC/1000;
+ cmap_u64_max_load_factor(&m, 0.8);
+ cmap_u64_reserve(&m, n);
+ printf("STC cmap n = %" PRIuMAX ", mask = 0x%" PRIxMAX "\n", n, mask);
+
+ uint64_t rng[3] = {1872361123, 123879177, 87739234}, sum;
+ clock_t now = clock();
+ c_forrange (n) {
+ uint64_t key = romu_trio(rng) & mask;
+ cmap_u64_insert(&m, key, 0).ref->second += 1;
+ }
+ printf("insert : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
+
+ now = clock();
+ sum = 0;
+ c_forrange (key, mask + 1) { sum += cmap_u64_contains(&m, key); }
+ printf("lookup : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
+
+ now = clock();
+ sum = 0;
+ c_foreach (i, cmap_u64, m) { sum += i.ref->second; }
+ printf("iterate : %zums \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum);
+
+ uint64_t rng2[3] = {1872361123, 123879177, 87739234};
+ now = clock();
+ c_forrange (n) {
+ uint64_t key = romu_trio(rng2) & mask;
+ cmap_u64_erase(&m, key);
+ }
+ printf("remove : %zums \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(m));
+ printf("press a key:\n"); getchar();
+ }
} \ No newline at end of file
diff --git a/benchmarks/picobench/picobench_cmap.cpp b/benchmarks/picobench/picobench_cmap.cpp
index 30170061..4a330019 100644
--- a/benchmarks/picobench/picobench_cmap.cpp
+++ b/benchmarks/picobench/picobench_cmap.cpp
@@ -1,302 +1,302 @@
-#define i_static
-#include <stc/crandom.h>
-#define i_static
-#include <stc/cstr.h>
-#include <cmath>
-#include <string>
-#include <unordered_map>
-#include <stdexcept>
-#include "../external/robin_hood.h"
-#include "../external/skarupke/bytell_hash_map.hpp"
-#include "../external/tsl/hopscotch_map.h"
-#include "../external/parallel_hashmap/phmap.h"
-
-#define PICOBENCH_IMPLEMENT_WITH_MAIN
-#include "picobench.hpp"
-
-enum {N1 = 4000000, S1 = 1, MaxLoadFactor100 = 80};
-uint64_t seed = time(NULL);
-
-template <class K, class V> using umap = std::unordered_map<K, V>;
-template <class K, class V> using bmap = ska::bytell_hash_map<K, V>;
-template <class K, class V> using fmap = ska::flat_hash_map<K, V>;
-template <class K, class V> using hmap = tsl::hopscotch_map<K, V>;
-template <class K, class V> using pmap = phmap::flat_hash_map<K, V>;
-template <class K, class V> using rmap = robin_hood::unordered_flat_map<K, V,
- robin_hood::hash<K>, std::equal_to<K>, MaxLoadFactor100>;
-#define DEFMAP(map, ...) \
- using u##map = umap __VA_ARGS__; \
- using b##map = bmap __VA_ARGS__; \
- using f##map = fmap __VA_ARGS__; \
- using h##map = hmap __VA_ARGS__; \
- using p##map = pmap __VA_ARGS__; \
- using r##map = rmap __VA_ARGS__
-
-
-DEFMAP(map_i, <int32_t, int32_t>);
-DEFMAP(map_x, <uint64_t, uint64_t>);
-DEFMAP(map_s, <std::string, std::string>);
-
-#define i_key int32_t
-#define i_val int32_t
-#define i_tag i
-#include <stc/cmap.h>
-
-#define i_key uint64_t
-#define i_val uint64_t
-#define i_tag x
-#include <stc/cmap.h>
-
-#define i_key_str
-#define i_val_str
-#include <stc/cmap.h>
-
-PICOBENCH_SUITE("Map1");
-
-template <class MapInt>
-static void ins_and_erase_i(picobench::state& s)
-{
- size_t result = 0;
- MapInt map;
- map.max_load_factor((int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations())
- map[crandom()];
- map.clear();
- csrandom(seed);
- c_forrange (s.iterations())
- map[crandom()];
- csrandom(seed);
- c_forrange (s.iterations())
- map.erase(crandom());
- s.set_result(map.size());
-}
-
-static void ins_and_erase_cmap_i(picobench::state& s)
-{
- cmap_i map = cmap_i_init();
- cmap_i_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations())
- cmap_i_insert(&map, crandom(), 0);
- cmap_i_clear(&map);
- csrandom(seed);
- c_forrange (s.iterations())
- cmap_i_insert(&map, crandom(), 0);
- csrandom(seed);
- c_forrange (s.iterations())
- cmap_i_erase(&map, crandom());
- s.set_result(cmap_i_size(map));
- cmap_i_drop(&map);
-}
-
-static void ins_and_erase_cmap_x(picobench::state& s)
-{
- cmap_x map = cmap_x_init();
- cmap_x_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations())
- cmap_x_insert(&map, crandom(), 0);
- cmap_x_clear(&map);
- csrandom(seed);
- c_forrange (s.iterations())
- cmap_x_insert(&map, crandom(), 0);
- csrandom(seed);
- c_forrange (s.iterations())
- cmap_x_erase(&map, crandom());
- s.set_result(cmap_x_size(map));
- cmap_x_drop(&map);
-}
-
-#define P samples(S1).iterations({N1/4})
-PICOBENCH(ins_and_erase_i<umap_x>).P;
-PICOBENCH(ins_and_erase_i<bmap_x>).P;
-PICOBENCH(ins_and_erase_i<fmap_x>).P;
-PICOBENCH(ins_and_erase_i<hmap_x>).P;
-PICOBENCH(ins_and_erase_i<pmap_x>).P;
-PICOBENCH(ins_and_erase_i<rmap_x>).P;
-PICOBENCH(ins_and_erase_cmap_x).P;
-#undef P
-
-PICOBENCH_SUITE("Map2");
-
-template <class MapInt>
-static void ins_and_access_i(picobench::state& s)
-{
- uint64_t mask = (1ull << s.arg()) - 1;
- size_t result = 0;
- MapInt map;
- map.max_load_factor((int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (N1)
- result += ++map[crandom() & mask];
- s.set_result(result);
-}
-
-static void ins_and_access_cmap_i(picobench::state& s)
-{
- uint64_t mask = (1ull << s.arg()) - 1;
- size_t result = 0;
- cmap_i map = cmap_i_init();
- cmap_i_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (N1)
- result += ++cmap_i_insert(&map, crandom() & mask, 0).ref->second;
- s.set_result(result);
- cmap_i_drop(&map);
-}
-
-#define P samples(S1).iterations({N1, N1, N1, N1}).args({18, 23, 25, 31})
-PICOBENCH(ins_and_access_i<umap_i>).P;
-PICOBENCH(ins_and_access_i<bmap_i>).P;
-PICOBENCH(ins_and_access_i<fmap_i>).P;
-PICOBENCH(ins_and_access_i<hmap_i>).P;
-PICOBENCH(ins_and_access_i<pmap_i>).P;
-PICOBENCH(ins_and_access_i<rmap_i>).P;
-PICOBENCH(ins_and_access_cmap_i).P;
-#undef P
-
-PICOBENCH_SUITE("Map3");
-
-static void randomize(char* str, size_t len) {
- for (int k=0; k < len; ++k) {
- union {uint64_t i; char c[8];} r = {.i = crandom()};
- for (int i=0; i<8 && k<len; ++k, ++i)
- str[k] = (r.c[i] & 63) + 48;
- }
-}
-
-template <class MapStr>
-static void ins_and_access_s(picobench::state& s)
-{
- std::string str(s.arg(), 'x');
- size_t result = 0;
- MapStr map;
- map.max_load_factor((int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations()) {
- randomize(&str[0], str.size());
- map.emplace(str, str);
- randomize(&str[0], str.size());
- result += map.erase(str);
- }
- s.set_result(result + map.size());
-}
-
-static void ins_and_access_cmap_s(picobench::state& s)
-{
- cstr str = cstr_with_size(s.arg(), 'x');
- char* buf = cstr_data(&str);
- size_t result = 0;
- cmap_str map = cmap_str_init();
- cmap_str_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations()) {
- randomize(buf, s.arg());
- //if (s.arg() > 30) { printf("%s\n", buf); exit(0); }
- cmap_str_emplace(&map, buf, buf);
-
- randomize(buf, s.arg());
- result += cmap_str_erase(&map, buf);
- }
- s.set_result(result + cmap_str_size(map));
- cstr_drop(&str);
- cmap_str_drop(&map);
-}
-
-#define P samples(S1).iterations({N1/5, N1/5, N1/5, N1/10, N1/40}).args({13, 7, 8, 100, 1000})
-PICOBENCH(ins_and_access_s<umap_s>).P;
-PICOBENCH(ins_and_access_s<bmap_s>).P;
-PICOBENCH(ins_and_access_s<fmap_s>).P;
-PICOBENCH(ins_and_access_s<hmap_s>).P;
-PICOBENCH(ins_and_access_s<pmap_s>).P;
-PICOBENCH(ins_and_access_s<rmap_s>).P;
-PICOBENCH(ins_and_access_cmap_s).P;
-#undef P
-
-PICOBENCH_SUITE("Map4");
-
-template <class MapX>
-static void iterate_x(picobench::state& s)
-{
- MapX map;
- map.max_load_factor((int)MaxLoadFactor100 / 100.0);
- uint64_t K = (1ull << s.arg()) - 1;
-
- picobench::scope scope(s);
- csrandom(seed);
- size_t result = 0;
-
- // measure insert then iterate whole map
- c_forrange (n, s.iterations()) {
- map[crandom()] = n;
- if (!(n & K)) for (auto const& keyVal : map)
- result += keyVal.second;
- }
-
- // reset rng back to inital state
- csrandom(seed);
-
- // measure erase then iterate whole map
- c_forrange (n, s.iterations()) {
- map.erase(crandom());
- if (!(n & K)) for (auto const& keyVal : map)
- result += keyVal.second;
- }
- s.set_result(result);
-}
-
-static void iterate_cmap_x(picobench::state& s)
-{
- cmap_x map = cmap_x_init();
- cmap_x_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
- uint64_t K = (1ull << s.arg()) - 1;
-
- picobench::scope scope(s);
- csrandom(seed);
- size_t result = 0;
-
- // measure insert then iterate whole map
- c_forrange (n, s.iterations()) {
- cmap_x_insert_or_assign(&map, crandom(), n);
- if (!(n & K)) c_foreach (i, cmap_x, map)
- result += i.ref->second;
- }
-
- // reset rng back to inital state
- csrandom(seed);
-
- // measure erase then iterate whole map
- c_forrange (n, s.iterations()) {
- cmap_x_erase(&map, crandom());
- if (!(n & K)) c_foreach (i, cmap_x, map)
- result += i.ref->second;
- }
- s.set_result(result);
- cmap_x_drop(&map);
-}
-
-
-#define P samples(S1).iterations({N1/20}).args({12})
-PICOBENCH(iterate_x<umap_x>).P;
-PICOBENCH(iterate_x<bmap_x>).P;
-PICOBENCH(iterate_x<fmap_x>).P;
-PICOBENCH(iterate_x<hmap_x>).P;
-PICOBENCH(iterate_x<pmap_x>).P;
-PICOBENCH(iterate_x<rmap_x>).P;
-PICOBENCH(iterate_cmap_x).P;
-#undef P
+#define i_static
+#include <stc/crandom.h>
+#define i_static
+#include <stc/cstr.h>
+#include <cmath>
+#include <string>
+#include <unordered_map>
+#include <stdexcept>
+#include "../external/robin_hood.h"
+#include "../external/skarupke/bytell_hash_map.hpp"
+#include "../external/tsl/hopscotch_map.h"
+#include "../external/parallel_hashmap/phmap.h"
+
+#define PICOBENCH_IMPLEMENT_WITH_MAIN
+#include "picobench.hpp"
+
+enum {N1 = 4000000, S1 = 1, MaxLoadFactor100 = 80};
+uint64_t seed = time(NULL);
+
+template <class K, class V> using umap = std::unordered_map<K, V>;
+template <class K, class V> using bmap = ska::bytell_hash_map<K, V>;
+template <class K, class V> using fmap = ska::flat_hash_map<K, V>;
+template <class K, class V> using hmap = tsl::hopscotch_map<K, V>;
+template <class K, class V> using pmap = phmap::flat_hash_map<K, V>;
+template <class K, class V> using rmap = robin_hood::unordered_flat_map<K, V,
+ robin_hood::hash<K>, std::equal_to<K>, MaxLoadFactor100>;
+#define DEFMAP(map, ...) \
+ using u##map = umap __VA_ARGS__; \
+ using b##map = bmap __VA_ARGS__; \
+ using f##map = fmap __VA_ARGS__; \
+ using h##map = hmap __VA_ARGS__; \
+ using p##map = pmap __VA_ARGS__; \
+ using r##map = rmap __VA_ARGS__
+
+
+DEFMAP(map_i, <int32_t, int32_t>);
+DEFMAP(map_x, <uint64_t, uint64_t>);
+DEFMAP(map_s, <std::string, std::string>);
+
+#define i_key int32_t
+#define i_val int32_t
+#define i_tag i
+#include <stc/cmap.h>
+
+#define i_key uint64_t
+#define i_val uint64_t
+#define i_tag x
+#include <stc/cmap.h>
+
+#define i_key_str
+#define i_val_str
+#include <stc/cmap.h>
+
+PICOBENCH_SUITE("Map1");
+
+template <class MapInt>
+static void ins_and_erase_i(picobench::state& s)
+{
+ size_t result = 0;
+ MapInt map;
+ map.max_load_factor((int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations())
+ map[crandom()];
+ map.clear();
+ csrandom(seed);
+ c_forrange (s.iterations())
+ map[crandom()];
+ csrandom(seed);
+ c_forrange (s.iterations())
+ map.erase(crandom());
+ s.set_result(map.size());
+}
+
+static void ins_and_erase_cmap_i(picobench::state& s)
+{
+ cmap_i map = cmap_i_init();
+ cmap_i_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations())
+ cmap_i_insert(&map, crandom(), 0);
+ cmap_i_clear(&map);
+ csrandom(seed);
+ c_forrange (s.iterations())
+ cmap_i_insert(&map, crandom(), 0);
+ csrandom(seed);
+ c_forrange (s.iterations())
+ cmap_i_erase(&map, crandom());
+ s.set_result(cmap_i_size(map));
+ cmap_i_drop(&map);
+}
+
+static void ins_and_erase_cmap_x(picobench::state& s)
+{
+ cmap_x map = cmap_x_init();
+ cmap_x_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations())
+ cmap_x_insert(&map, crandom(), 0);
+ cmap_x_clear(&map);
+ csrandom(seed);
+ c_forrange (s.iterations())
+ cmap_x_insert(&map, crandom(), 0);
+ csrandom(seed);
+ c_forrange (s.iterations())
+ cmap_x_erase(&map, crandom());
+ s.set_result(cmap_x_size(map));
+ cmap_x_drop(&map);
+}
+
+#define P samples(S1).iterations({N1/4})
+PICOBENCH(ins_and_erase_i<umap_x>).P;
+PICOBENCH(ins_and_erase_i<bmap_x>).P;
+PICOBENCH(ins_and_erase_i<fmap_x>).P;
+PICOBENCH(ins_and_erase_i<hmap_x>).P;
+PICOBENCH(ins_and_erase_i<pmap_x>).P;
+PICOBENCH(ins_and_erase_i<rmap_x>).P;
+PICOBENCH(ins_and_erase_cmap_x).P;
+#undef P
+
+PICOBENCH_SUITE("Map2");
+
+template <class MapInt>
+static void ins_and_access_i(picobench::state& s)
+{
+ uint64_t mask = (1ull << s.arg()) - 1;
+ size_t result = 0;
+ MapInt map;
+ map.max_load_factor((int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (N1)
+ result += ++map[crandom() & mask];
+ s.set_result(result);
+}
+
+static void ins_and_access_cmap_i(picobench::state& s)
+{
+ uint64_t mask = (1ull << s.arg()) - 1;
+ size_t result = 0;
+ cmap_i map = cmap_i_init();
+ cmap_i_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (N1)
+ result += ++cmap_i_insert(&map, crandom() & mask, 0).ref->second;
+ s.set_result(result);
+ cmap_i_drop(&map);
+}
+
+#define P samples(S1).iterations({N1, N1, N1, N1}).args({18, 23, 25, 31})
+PICOBENCH(ins_and_access_i<umap_i>).P;
+PICOBENCH(ins_and_access_i<bmap_i>).P;
+PICOBENCH(ins_and_access_i<fmap_i>).P;
+PICOBENCH(ins_and_access_i<hmap_i>).P;
+PICOBENCH(ins_and_access_i<pmap_i>).P;
+PICOBENCH(ins_and_access_i<rmap_i>).P;
+PICOBENCH(ins_and_access_cmap_i).P;
+#undef P
+
+PICOBENCH_SUITE("Map3");
+
+static void randomize(char* str, size_t len) {
+ for (int k=0; k < len; ++k) {
+ union {uint64_t i; char c[8];} r = {.i = crandom()};
+ for (int i=0; i<8 && k<len; ++k, ++i)
+ str[k] = (r.c[i] & 63) + 48;
+ }
+}
+
+template <class MapStr>
+static void ins_and_access_s(picobench::state& s)
+{
+ std::string str(s.arg(), 'x');
+ size_t result = 0;
+ MapStr map;
+ map.max_load_factor((int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations()) {
+ randomize(&str[0], str.size());
+ map.emplace(str, str);
+ randomize(&str[0], str.size());
+ result += map.erase(str);
+ }
+ s.set_result(result + map.size());
+}
+
+static void ins_and_access_cmap_s(picobench::state& s)
+{
+ cstr str = cstr_with_size(s.arg(), 'x');
+ char* buf = cstr_data(&str);
+ size_t result = 0;
+ cmap_str map = cmap_str_init();
+ cmap_str_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations()) {
+ randomize(buf, s.arg());
+ //if (s.arg() > 30) { printf("%s\n", buf); exit(0); }
+ cmap_str_emplace(&map, buf, buf);
+
+ randomize(buf, s.arg());
+ result += cmap_str_erase(&map, buf);
+ }
+ s.set_result(result + cmap_str_size(map));
+ cstr_drop(&str);
+ cmap_str_drop(&map);
+}
+
+#define P samples(S1).iterations({N1/5, N1/5, N1/5, N1/10, N1/40}).args({13, 7, 8, 100, 1000})
+PICOBENCH(ins_and_access_s<umap_s>).P;
+PICOBENCH(ins_and_access_s<bmap_s>).P;
+PICOBENCH(ins_and_access_s<fmap_s>).P;
+PICOBENCH(ins_and_access_s<hmap_s>).P;
+PICOBENCH(ins_and_access_s<pmap_s>).P;
+PICOBENCH(ins_and_access_s<rmap_s>).P;
+PICOBENCH(ins_and_access_cmap_s).P;
+#undef P
+
+PICOBENCH_SUITE("Map4");
+
+template <class MapX>
+static void iterate_x(picobench::state& s)
+{
+ MapX map;
+ map.max_load_factor((int)MaxLoadFactor100 / 100.0);
+ uint64_t K = (1ull << s.arg()) - 1;
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ size_t result = 0;
+
+ // measure insert then iterate whole map
+ c_forrange (n, s.iterations()) {
+ map[crandom()] = n;
+ if (!(n & K)) for (auto const& keyVal : map)
+ result += keyVal.second;
+ }
+
+ // reset rng back to inital state
+ csrandom(seed);
+
+ // measure erase then iterate whole map
+ c_forrange (n, s.iterations()) {
+ map.erase(crandom());
+ if (!(n & K)) for (auto const& keyVal : map)
+ result += keyVal.second;
+ }
+ s.set_result(result);
+}
+
+static void iterate_cmap_x(picobench::state& s)
+{
+ cmap_x map = cmap_x_init();
+ cmap_x_max_load_factor(&map, (int)MaxLoadFactor100 / 100.0);
+ uint64_t K = (1ull << s.arg()) - 1;
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ size_t result = 0;
+
+ // measure insert then iterate whole map
+ c_forrange (n, s.iterations()) {
+ cmap_x_insert_or_assign(&map, crandom(), n);
+ if (!(n & K)) c_foreach (i, cmap_x, map)
+ result += i.ref->second;
+ }
+
+ // reset rng back to inital state
+ csrandom(seed);
+
+ // measure erase then iterate whole map
+ c_forrange (n, s.iterations()) {
+ cmap_x_erase(&map, crandom());
+ if (!(n & K)) c_foreach (i, cmap_x, map)
+ result += i.ref->second;
+ }
+ s.set_result(result);
+ cmap_x_drop(&map);
+}
+
+
+#define P samples(S1).iterations({N1/20}).args({12})
+PICOBENCH(iterate_x<umap_x>).P;
+PICOBENCH(iterate_x<bmap_x>).P;
+PICOBENCH(iterate_x<fmap_x>).P;
+PICOBENCH(iterate_x<hmap_x>).P;
+PICOBENCH(iterate_x<pmap_x>).P;
+PICOBENCH(iterate_x<rmap_x>).P;
+PICOBENCH(iterate_cmap_x).P;
+#undef P
diff --git a/benchmarks/picobench/picobench_csmap.cpp b/benchmarks/picobench/picobench_csmap.cpp
index 3f203cc8..ea2174fa 100644
--- a/benchmarks/picobench/picobench_csmap.cpp
+++ b/benchmarks/picobench/picobench_csmap.cpp
@@ -1,322 +1,322 @@
-#include <iostream>
-#define i_static
-#include <stc/crandom.h>
-#define i_static
-#include <stc/cstr.h>
-#include <cmath>
-#include <string>
-#include <map>
-
-#define PICOBENCH_IMPLEMENT_WITH_MAIN
-#include "picobench.hpp"
-
-enum {N1 = 1000000, S1 = 1};
-uint64_t seed = time(NULL); // 18237129837891;
-
-using omap_i = std::map<int, int>;
-using omap_x = std::map<uint64_t, uint64_t>;
-using omap_s = std::map<std::string, std::string>;
-
-#define i_key int
-#define i_val int
-#define i_tag i
-#include <stc/csmap.h>
-
-#define i_key size_t
-#define i_val size_t
-#define i_tag x
-#include <stc/csmap.h>
-
-#define i_key_str
-#define i_val_str
-#include <stc/csmap.h>
-
-PICOBENCH_SUITE("Map1");
-
-template <class MapInt>
-static void ctor_and_ins_one_i(picobench::state& s)
-{
- size_t result = 0;
- picobench::scope scope(s);
- c_forrange (n, s.iterations()) {
- MapInt map;
- map[n];
- result += map.size();
- }
- s.set_result(result);
-}
-
-static void ctor_and_ins_one_csmap_i(picobench::state& s)
-{
- size_t result = 0;
- picobench::scope scope(s);
- c_forrange (n, s.iterations()) {
- csmap_i map = csmap_i_init();
- csmap_i_insert(&map, n, 0);
- result += csmap_i_size(map);
- csmap_i_drop(&map);
- }
- s.set_result(result);
-}
-
-#define P samples(S1).iterations({N1})
-//PICOBENCH(ctor_and_ins_one_i<omap_i>).P;
-//PICOBENCH(ctor_and_ins_one_csmap_i).P;
-#undef P
-
-
-PICOBENCH_SUITE("Map_insert_only");
-
-template <class MapInt>
-static void insert_i(picobench::state& s)
-{
- size_t result = 0;
- MapInt map;
- csrandom(seed);
- picobench::scope scope(s);
- c_forrange (n, s.iterations())
- map.emplace(crandom() & 0xfffffff, n);
- s.set_result(map.size());
-}
-
-static void insert_csmap_i(picobench::state& s)
-{
- size_t result = 0;
- csmap_i map = csmap_i_init();
- csrandom(seed);
- picobench::scope scope(s);
- c_forrange (n, s.iterations())
- csmap_i_insert(&map, crandom() & 0xfffffff, n);
- s.set_result(csmap_i_size(map));
- csmap_i_drop(&map);
-}
-
-#define P samples(S1).iterations({N1})
-PICOBENCH(insert_i<omap_i>).P;
-PICOBENCH(insert_csmap_i).P;
-#undef P
-
-
-PICOBENCH_SUITE("Map2");
-
-template <class MapInt>
-static void ins_and_erase_i(picobench::state& s)
-{
- size_t result = 0;
- uint64_t mask = (1ull << s.arg()) - 1;
- MapInt map;
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (i, s.iterations())
- map.emplace(crandom() & mask, i);
- result = map.size();
-
- map.clear();
- csrandom(seed);
- c_forrange (i, s.iterations())
- map[crandom() & mask] = i;
-
- csrandom(seed);
- c_forrange (s.iterations())
- map.erase(crandom() & mask);
- s.set_result(result);
-}
-
-static void ins_and_erase_csmap_i(picobench::state& s)
-{
- size_t result = 0;
- uint64_t mask = (1ull << s.arg()) - 1;
- csmap_i map = csmap_i_init();
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (i, s.iterations())
- csmap_i_insert(&map, crandom() & mask, i);
- result = csmap_i_size(map);
-
- csmap_i_clear(&map);
- csrandom(seed);
- c_forrange (i, s.iterations())
- csmap_i_insert_or_assign(&map, crandom() & mask, i);
-
- csrandom(seed);
- c_forrange (s.iterations())
- csmap_i_erase(&map, crandom() & mask);
- s.set_result(result);
- csmap_i_drop(&map);
-}
-
-#define P samples(S1).iterations({N1/2, N1/2, N1/2, N1/2}).args({18, 23, 25, 31})
-PICOBENCH(ins_and_erase_i<omap_i>).P;
-PICOBENCH(ins_and_erase_csmap_i).P;
-#undef P
-
-PICOBENCH_SUITE("Map3");
-
-template <class MapInt>
-static void ins_and_access_i(picobench::state& s)
-{
- uint64_t mask = (1ull << s.arg()) - 1;
- size_t result = 0;
- MapInt map;
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations()) {
- result += ++map[crandom() & mask];
- auto it = map.find(crandom() & mask);
- if (it != map.end()) map.erase(it->first);
- }
- s.set_result(result + map.size());
-}
-
-static void ins_and_access_csmap_i(picobench::state& s)
-{
- uint64_t mask = (1ull << s.arg()) - 1;
- size_t result = 0;
- csmap_i map = csmap_i_init();
- csrandom(seed);
-
- picobench::scope scope(s);
- c_forrange (s.iterations()) {
- result += ++csmap_i_insert(&map, crandom() & mask, 0).ref->second;
- const csmap_i_value* val = csmap_i_get(&map, crandom() & mask);
- if (val) csmap_i_erase(&map, val->first);
- }
- s.set_result(result + csmap_i_size(map));
- csmap_i_drop(&map);
-}
-
-#define P samples(S1).iterations({N1, N1, N1, N1}).args({18, 23, 25, 31})
-PICOBENCH(ins_and_access_i<omap_i>).P;
-PICOBENCH(ins_and_access_csmap_i).P;
-#undef P
-
-PICOBENCH_SUITE("Map4");
-
-static void randomize(char* str, size_t len) {
- union {uint64_t i; char c[8];} r = {.i = crandom()};
- for (int i = len - 7, j = 0; i < len; ++j, ++i)
- str[i] = (r.c[j] & 63) + 48;
-}
-
-template <class MapStr>
-static void ins_and_access_s(picobench::state& s)
-{
- std::string str(s.arg(), 'x');
- size_t result = 0;
- MapStr map;
-
- picobench::scope scope(s);
- csrandom(seed);
- c_forrange (s.iterations()) {
- randomize(&str[0], str.size());
- map.emplace(str, str);
- }
- csrandom(seed);
- c_forrange (s.iterations()) {
- randomize(&str[0], str.size());
- result += map.erase(str);
- }
- s.set_result(result + map.size());
-}
-
-static void ins_and_access_csmap_s(picobench::state& s)
-{
- cstr str = cstr_with_size(s.arg(), 'x');
- char* buf = cstr_data(&str);
- size_t result = 0;
- csmap_str map = csmap_str_init();
-
- picobench::scope scope(s);
- csrandom(seed);
- c_forrange (s.iterations()) {
- randomize(buf, s.arg());
- csmap_str_emplace(&map, buf, buf);
- }
- csrandom(seed);
- c_forrange (s.iterations()) {
- randomize(buf, s.arg());
- result += csmap_str_erase(&map, buf);
- /*csmap_str_iter it = csmap_str_find(&map, buf);
- if (it.ref) {
- ++result;
- csmap_str_erase(&map, cstr_str(&it.ref->first));
- }*/
- }
- s.set_result(result + csmap_str_size(map));
- cstr_drop(&str);
- csmap_str_drop(&map);
-}
-
-#define P samples(S1).iterations({N1/5, N1/5, N1/5, N1/10, N1/40}).args({13, 7, 8, 100, 1000})
-PICOBENCH(ins_and_access_s<omap_s>).P;
-PICOBENCH(ins_and_access_csmap_s).P;
-#undef P
-
-PICOBENCH_SUITE("Map5");
-
-template <class MapX>
-static void iterate_x(picobench::state& s)
-{
- MapX map;
- uint64_t K = (1ull << s.arg()) - 1;
-
- picobench::scope scope(s);
- csrandom(seed);
- size_t result = 0;
-
- // measure insert then iterate whole map
- c_forrange (n, s.iterations()) {
- map[crandom()] = n;
- if (!(n & K)) for (auto const& keyVal : map)
- result += keyVal.second;
- }
-
- // reset rng back to inital state
- csrandom(seed);
-
- // measure erase then iterate whole map
- c_forrange (n, s.iterations()) {
- map.erase(crandom());
- if (!(n & K)) for (auto const& keyVal : map)
- result += keyVal.second;
- }
- s.set_result(result);
-}
-
-static void iterate_csmap_x(picobench::state& s)
-{
- csmap_x map = csmap_x_init();
- uint64_t K = (1ull << s.arg()) - 1;
-
- picobench::scope scope(s);
- csrandom(seed);
- size_t result = 0;
-
- // measure insert then iterate whole map
- c_forrange (n, s.iterations()) {
- csmap_x_insert_or_assign(&map, crandom(), n);
- if (!(n & K)) c_foreach (i, csmap_x, map)
- result += i.ref->second;
- }
-
- // reset rng back to inital state
- csrandom(seed);
-
- // measure erase then iterate whole map
- c_forrange (n, s.iterations()) {
- csmap_x_erase(&map, crandom());
- if (!(n & K)) c_foreach (i, csmap_x, map)
- result += i.ref->second;
- }
- s.set_result(result);
- csmap_x_drop(&map);
-}
-
-
-#define P samples(S1).iterations({N1/20}).args({12})
-//PICOBENCH(iterate_x<omap_x>).P;
-//PICOBENCH(iterate_csmap_x).P;
-#undef P
+#include <iostream>
+#define i_static
+#include <stc/crandom.h>
+#define i_static
+#include <stc/cstr.h>
+#include <cmath>
+#include <string>
+#include <map>
+
+#define PICOBENCH_IMPLEMENT_WITH_MAIN
+#include "picobench.hpp"
+
+enum {N1 = 1000000, S1 = 1};
+uint64_t seed = time(NULL); // 18237129837891;
+
+using omap_i = std::map<int, int>;
+using omap_x = std::map<uint64_t, uint64_t>;
+using omap_s = std::map<std::string, std::string>;
+
+#define i_key int
+#define i_val int
+#define i_tag i
+#include <stc/csmap.h>
+
+#define i_key size_t
+#define i_val size_t
+#define i_tag x
+#include <stc/csmap.h>
+
+#define i_key_str
+#define i_val_str
+#include <stc/csmap.h>
+
+PICOBENCH_SUITE("Map1");
+
+template <class MapInt>
+static void ctor_and_ins_one_i(picobench::state& s)
+{
+ size_t result = 0;
+ picobench::scope scope(s);
+ c_forrange (n, s.iterations()) {
+ MapInt map;
+ map[n];
+ result += map.size();
+ }
+ s.set_result(result);
+}
+
+static void ctor_and_ins_one_csmap_i(picobench::state& s)
+{
+ size_t result = 0;
+ picobench::scope scope(s);
+ c_forrange (n, s.iterations()) {
+ csmap_i map = csmap_i_init();
+ csmap_i_insert(&map, n, 0);
+ result += csmap_i_size(map);
+ csmap_i_drop(&map);
+ }
+ s.set_result(result);
+}
+
+#define P samples(S1).iterations({N1})
+//PICOBENCH(ctor_and_ins_one_i<omap_i>).P;
+//PICOBENCH(ctor_and_ins_one_csmap_i).P;
+#undef P
+
+
+PICOBENCH_SUITE("Map_insert_only");
+
+template <class MapInt>
+static void insert_i(picobench::state& s)
+{
+ size_t result = 0;
+ MapInt map;
+ csrandom(seed);
+ picobench::scope scope(s);
+ c_forrange (n, s.iterations())
+ map.emplace(crandom() & 0xfffffff, n);
+ s.set_result(map.size());
+}
+
+static void insert_csmap_i(picobench::state& s)
+{
+ size_t result = 0;
+ csmap_i map = csmap_i_init();
+ csrandom(seed);
+ picobench::scope scope(s);
+ c_forrange (n, s.iterations())
+ csmap_i_insert(&map, crandom() & 0xfffffff, n);
+ s.set_result(csmap_i_size(map));
+ csmap_i_drop(&map);
+}
+
+#define P samples(S1).iterations({N1})
+PICOBENCH(insert_i<omap_i>).P;
+PICOBENCH(insert_csmap_i).P;
+#undef P
+
+
+PICOBENCH_SUITE("Map2");
+
+template <class MapInt>
+static void ins_and_erase_i(picobench::state& s)
+{
+ size_t result = 0;
+ uint64_t mask = (1ull << s.arg()) - 1;
+ MapInt map;
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (i, s.iterations())
+ map.emplace(crandom() & mask, i);
+ result = map.size();
+
+ map.clear();
+ csrandom(seed);
+ c_forrange (i, s.iterations())
+ map[crandom() & mask] = i;
+
+ csrandom(seed);
+ c_forrange (s.iterations())
+ map.erase(crandom() & mask);
+ s.set_result(result);
+}
+
+static void ins_and_erase_csmap_i(picobench::state& s)
+{
+ size_t result = 0;
+ uint64_t mask = (1ull << s.arg()) - 1;
+ csmap_i map = csmap_i_init();
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (i, s.iterations())
+ csmap_i_insert(&map, crandom() & mask, i);
+ result = csmap_i_size(map);
+
+ csmap_i_clear(&map);
+ csrandom(seed);
+ c_forrange (i, s.iterations())
+ csmap_i_insert_or_assign(&map, crandom() & mask, i);
+
+ csrandom(seed);
+ c_forrange (s.iterations())
+ csmap_i_erase(&map, crandom() & mask);
+ s.set_result(result);
+ csmap_i_drop(&map);
+}
+
+#define P samples(S1).iterations({N1/2, N1/2, N1/2, N1/2}).args({18, 23, 25, 31})
+PICOBENCH(ins_and_erase_i<omap_i>).P;
+PICOBENCH(ins_and_erase_csmap_i).P;
+#undef P
+
+PICOBENCH_SUITE("Map3");
+
+template <class MapInt>
+static void ins_and_access_i(picobench::state& s)
+{
+ uint64_t mask = (1ull << s.arg()) - 1;
+ size_t result = 0;
+ MapInt map;
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations()) {
+ result += ++map[crandom() & mask];
+ auto it = map.find(crandom() & mask);
+ if (it != map.end()) map.erase(it->first);
+ }
+ s.set_result(result + map.size());
+}
+
+static void ins_and_access_csmap_i(picobench::state& s)
+{
+ uint64_t mask = (1ull << s.arg()) - 1;
+ size_t result = 0;
+ csmap_i map = csmap_i_init();
+ csrandom(seed);
+
+ picobench::scope scope(s);
+ c_forrange (s.iterations()) {
+ result += ++csmap_i_insert(&map, crandom() & mask, 0).ref->second;
+ const csmap_i_value* val = csmap_i_get(&map, crandom() & mask);
+ if (val) csmap_i_erase(&map, val->first);
+ }
+ s.set_result(result + csmap_i_size(map));
+ csmap_i_drop(&map);
+}
+
+#define P samples(S1).iterations({N1, N1, N1, N1}).args({18, 23, 25, 31})
+PICOBENCH(ins_and_access_i<omap_i>).P;
+PICOBENCH(ins_and_access_csmap_i).P;
+#undef P
+
+PICOBENCH_SUITE("Map4");
+
+static void randomize(char* str, size_t len) {
+ union {uint64_t i; char c[8];} r = {.i = crandom()};
+ for (int i = len - 7, j = 0; i < len; ++j, ++i)
+ str[i] = (r.c[j] & 63) + 48;
+}
+
+template <class MapStr>
+static void ins_and_access_s(picobench::state& s)
+{
+ std::string str(s.arg(), 'x');
+ size_t result = 0;
+ MapStr map;
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ c_forrange (s.iterations()) {
+ randomize(&str[0], str.size());
+ map.emplace(str, str);
+ }
+ csrandom(seed);
+ c_forrange (s.iterations()) {
+ randomize(&str[0], str.size());
+ result += map.erase(str);
+ }
+ s.set_result(result + map.size());
+}
+
+static void ins_and_access_csmap_s(picobench::state& s)
+{
+ cstr str = cstr_with_size(s.arg(), 'x');
+ char* buf = cstr_data(&str);
+ size_t result = 0;
+ csmap_str map = csmap_str_init();
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ c_forrange (s.iterations()) {
+ randomize(buf, s.arg());
+ csmap_str_emplace(&map, buf, buf);
+ }
+ csrandom(seed);
+ c_forrange (s.iterations()) {
+ randomize(buf, s.arg());
+ result += csmap_str_erase(&map, buf);
+ /*csmap_str_iter it = csmap_str_find(&map, buf);
+ if (it.ref) {
+ ++result;
+ csmap_str_erase(&map, cstr_str(&it.ref->first));
+ }*/
+ }
+ s.set_result(result + csmap_str_size(map));
+ cstr_drop(&str);
+ csmap_str_drop(&map);
+}
+
+#define P samples(S1).iterations({N1/5, N1/5, N1/5, N1/10, N1/40}).args({13, 7, 8, 100, 1000})
+PICOBENCH(ins_and_access_s<omap_s>).P;
+PICOBENCH(ins_and_access_csmap_s).P;
+#undef P
+
+PICOBENCH_SUITE("Map5");
+
+template <class MapX>
+static void iterate_x(picobench::state& s)
+{
+ MapX map;
+ uint64_t K = (1ull << s.arg()) - 1;
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ size_t result = 0;
+
+ // measure insert then iterate whole map
+ c_forrange (n, s.iterations()) {
+ map[crandom()] = n;
+ if (!(n & K)) for (auto const& keyVal : map)
+ result += keyVal.second;
+ }
+
+ // reset rng back to inital state
+ csrandom(seed);
+
+ // measure erase then iterate whole map
+ c_forrange (n, s.iterations()) {
+ map.erase(crandom());
+ if (!(n & K)) for (auto const& keyVal : map)
+ result += keyVal.second;
+ }
+ s.set_result(result);
+}
+
+static void iterate_csmap_x(picobench::state& s)
+{
+ csmap_x map = csmap_x_init();
+ uint64_t K = (1ull << s.arg()) - 1;
+
+ picobench::scope scope(s);
+ csrandom(seed);
+ size_t result = 0;
+
+ // measure insert then iterate whole map
+ c_forrange (n, s.iterations()) {
+ csmap_x_insert_or_assign(&map, crandom(), n);
+ if (!(n & K)) c_foreach (i, csmap_x, map)
+ result += i.ref->second;
+ }
+
+ // reset rng back to inital state
+ csrandom(seed);
+
+ // measure erase then iterate whole map
+ c_forrange (n, s.iterations()) {
+ csmap_x_erase(&map, crandom());
+ if (!(n & K)) c_foreach (i, csmap_x, map)
+ result += i.ref->second;
+ }
+ s.set_result(result);
+ csmap_x_drop(&map);
+}
+
+
+#define P samples(S1).iterations({N1/20}).args({12})
+//PICOBENCH(iterate_x<omap_x>).P;
+//PICOBENCH(iterate_csmap_x).P;
+#undef P
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);
+}