diff options
| author | Tyge Løvset <[email protected]> | 2020-10-21 11:44:08 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-10-21 11:44:08 +0200 |
| commit | b58093ac37d62cdc4736f6d916ce438413391266 (patch) | |
| tree | c8f32af316aad4c5edc32c7d6bc7a6829e8b5136 | |
| parent | d0d004c8154a40fdcfd5a86b04bc5c610dbcc386 (diff) | |
| download | STC-modified-b58093ac37d62cdc4736f6d916ce438413391266.tar.gz STC-modified-b58093ac37d62cdc4736f6d916ce438413391266.zip | |
Small update.
| -rw-r--r-- | examples/benchmark.c | 20 | ||||
| -rw-r--r-- | stc/cfmt.h | 35 |
2 files changed, 29 insertions, 26 deletions
diff --git a/examples/benchmark.c b/examples/benchmark.c index dd0001a7..b9da16f7 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -1,5 +1,5 @@ #include <stc/crandom.h>
-#include <stc/cstr.h>
+#include <stc/cfmt.h>
#include <stc/cmap.h>
#include "others/khash.h"
@@ -151,7 +151,7 @@ int rr = RR; erased += M##_ERASE(X, RAND(rr)); \
} \
difference = clock() - before; \
- printf(#M ": time: %5.02f, sum: %zu, erased %zu, size: %zu, buckets: %8zu\n", \
+ c_print(0, #M ": time: {:5.02f}, sum: {}, erased {}, size: {}, buckets: {:8}\n", \
(float) difference / CLOCKS_PER_SEC, checksum, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \
M##_CLEAR(X); \
}
@@ -166,7 +166,7 @@ int rr = RR; for (size_t i = 0; i < N2; ++i) \
erased += M##_ERASE(X, i); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, erased %zu, size: %zu, buckets: %8zu\n", \
+ c_print(0, #M ": time: {:5.02f}, erased {}, size: {}, buckets: {:8}\n", \
(float) difference / CLOCKS_PER_SEC, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \
M##_CLEAR(X); \
}
@@ -183,7 +183,7 @@ int rr = RR; for (size_t i = 0; i < N3; ++i) \
erased += M##_ERASE(X, RAND(rr)); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, erased %zu, size: %zu, buckets: %8zu\n", \
+ c_print(0, #M ": time: {:5.02f}, erased {}, size: {}, buckets: {:8}\n", \
(float) difference / CLOCKS_PER_SEC, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \
M##_CLEAR(X); \
}
@@ -199,7 +199,7 @@ int rr = RR; for (int k=0; k<5; k++) M##_FOR (X, i) \
sum += M##_ITEM(X, i); \
difference = clock() - before; \
- printf(#M ": time: %5.02f, sum %zu, size: %zu, buckets: %8zu\n", \
+ c_print(0, #M ": time: {:5.02f}, sum {}, size: {}, buckets: {:8}\n", \
(float) difference / CLOCKS_PER_SEC, sum, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \
M##_CLEAR(X); \
}
@@ -219,16 +219,16 @@ int main(int argc, char* argv[]) {
rr = argc == 2 ? atoi(argv[1]) : RR;
seed = time(NULL);
- printf("\nRandom keys are in range [0, 2^%d), seed = %zu:\n", rr, seed);
- printf("\nUnordered maps: %d repeats of Insert random key + try to remove a random key:\n", N1);
+ c_print(0, "\nRandom keys are in range [0, 2^%d), seed = %zu:\n", rr, seed);
+ c_print(0, "\nUnordered maps: %d repeats of Insert random key + try to remove a random key:\n", N1);
RUN_TEST(1)
- printf("\nUnordered maps: Insert %d index keys, then remove them in same order:\n", N2);
+ c_print(0, "\nUnordered maps: Insert %d index keys, then remove them in same order:\n", N2);
RUN_TEST(2)
- printf("\nUnordered maps: Insert %d random keys, then remove them in same order:\n", N3);
+ c_print(0, "\nUnordered maps: Insert %d random keys, then remove them in same order:\n", N3);
RUN_TEST(3)
- printf("\nUnordered maps: Iterate %d random keys:\n", N4);
+ c_print(0, "\nUnordered maps: Iterate %d random keys:\n", N4);
RUNX_TEST(4)
}
@@ -79,54 +79,57 @@ _cfmt_conv(const char *fmt, ...); #endif
#define c_print(...) c_MACRO_OVERLOAD(c_print, __VA_ARGS__)
+#define c_print_2(to, fmt) \
+ do { char *_fm = _cfmt_conv(fmt); \
+ _cfmt_fn(to)(to, _fm); free(_fm); } while (0)
#define c_print_3(to, fmt, c) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c)); \
- _cfmt_fn(to)(to, _fm, c); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c); free(_fm); } while (0)
#define c_print_4(to, fmt, c, d) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d)); \
- _cfmt_fn(to)(to, _fm, c, d); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d); free(_fm); } while (0)
#define c_print_5(to, fmt, c, d, e) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e)); \
- _cfmt_fn(to)(to, _fm, c, d, e); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e); free(_fm); } while (0)
#define c_print_6(to, fmt, c, d, e, f) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f); free(_fm); } while (0)
#define c_print_7(to, fmt, c, d, e, f, g) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g); free(_fm); } while (0)
#define c_print_8(to, fmt, c, d, e, f, g, h) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h); free(_fm); } while (0)
#define c_print_9(to, fmt, c, d, e, f, g, h, i) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i); free(_fm); } while (0)
#define c_print_10(to, fmt, c, d, e, f, g, h, i, j) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j); free(_fm); } while (0)
#define c_print_11(to, fmt, c, d, e, f, g, h, i, j, k) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k); free(_fm); } while (0)
#define c_print_12(to, fmt, c, d, e, f, g, h, i, j, k, m) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m); free(_fm); } while (0)
#define c_print_13(to, fmt, c, d, e, f, g, h, i, j, k, m, n) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n); free(_fm); } while (0)
#define c_print_14(to, fmt, c, d, e, f, g, h, i, j, k, m, n, o) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n), _cfmt(o)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o); free(_fm); } while (0)
#define c_print_15(to, fmt, c, d, e, f, g, h, i, j, k, m, n, o, p) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n), _cfmt(o), _cfmt(p)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p); free(_fm); } while (0)
#define c_print_16(to, fmt, c, d, e, f, g, h, i, j, k, m, n, o, p, q) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n), _cfmt(o), _cfmt(p), _cfmt(p)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q); free(_fm); } while (0)
#define c_print_17(to, fmt, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n), _cfmt(o), _cfmt(p), _cfmt(p), _cfmt(r)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r); free(_fm); } while (0)
#define c_print_18(to, fmt, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r, s) \
do { char *_fm = _cfmt_conv(fmt, _cfmt(c), _cfmt(d), _cfmt(e), _cfmt(f), _cfmt(g), _cfmt(h), _cfmt(i), _cfmt(j), _cfmt(k), _cfmt(m), _cfmt(n), _cfmt(o), _cfmt(p), _cfmt(p), _cfmt(r), _cfmt(s)); \
- _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r, s); free(_fm); } while (0)
+ _cfmt_fn(to)(to, _fm, c, d, e, f, g, h, i, j, k, m, n, o, p, q, r, s); free(_fm); } while (0)
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
|
