| 1 | #include <stdio.h> |
| 2 | #include <time.h> |
| 3 | #include <roaring/portability.h> |
| 4 | #include <roaring/containers/array.h> |
| 5 | #include <roaring/containers/bitset.h> |
| 6 | #include <roaring/containers/run.h> |
| 7 | #include <roaring/containers/mixed_equal.h> |
| 8 | #include "benchmark.h" |
| 9 | #include "random.h" |
| 10 | |
| 11 | int32_t array_container_get_nruns(const array_container_t *c) { (void) c; return -1; } |
| 12 | int32_t bitset_container_get_nruns(const bitset_container_t *c) { (void) c; return -1; } |
| 13 | int32_t run_container_get_nruns(const run_container_t *c) { return c->n_runs; } |
| 14 | |
| 15 | #define BENCHMARK_CONTAINER(cname1, cname2, fname, n) \ |
| 16 | { \ |
| 17 | cname1##_container_t *c1 = cname1##_container_create(); \ |
| 18 | cname2##_container_t *c2 = cname2##_container_create(); \ |
| 19 | uint16_t* values = malloc(0x10000 * sizeof(uint16_t)); \ |
| 20 | for (uint32_t i = 0; i < 0x10000; i++) { \ |
| 21 | values[i] = i; \ |
| 22 | } \ |
| 23 | shuffle_uint16(values, 0x10000); \ |
| 24 | for (uint32_t i = 0; i < n; i++) { \ |
| 25 | cname1##_container_add(c1, values[i]); \ |
| 26 | cname2##_container_add(c2, values[i]); \ |
| 27 | } \ |
| 28 | free(values); \ |
| 29 | printf("[Size:%5u] ", n); \ |
| 30 | printf("[NRuns:%5d] ", cname1##_container_get_nruns(c1)); \ |
| 31 | printf("[NRuns:%5d] ", cname2##_container_get_nruns(c2)); \ |
| 32 | BEST_TIME(fname(c1, c2), true, repeat, 1); \ |
| 33 | cname1##_container_free(c1); \ |
| 34 | cname2##_container_free(c2); \ |
| 35 | } |
| 36 | |
| 37 | int main(int argc, char* argv[]) { |
| 38 | (void)argc; |
| 39 | (void)argv; |
| 40 | const int repeat = 100*1000; |
| 41 | |
| 42 | BENCHMARK_CONTAINER(array, array, array_container_equals, 64); |
| 43 | BENCHMARK_CONTAINER(array, array, array_container_equals, DEFAULT_MAX_SIZE); |
| 44 | BENCHMARK_CONTAINER(array, array, array_container_equals, 2*DEFAULT_MAX_SIZE); |
| 45 | BENCHMARK_CONTAINER(bitset, bitset, bitset_container_equals, 65535); |
| 46 | BENCHMARK_CONTAINER(bitset, bitset, bitset_container_equals, 65536); |
| 47 | BENCHMARK_CONTAINER(run, run, run_container_equals, DEFAULT_MAX_SIZE/2); |
| 48 | BENCHMARK_CONTAINER(run, run, run_container_equals, DEFAULT_MAX_SIZE); |
| 49 | BENCHMARK_CONTAINER(run, array, run_container_equals_array, DEFAULT_MAX_SIZE); |
| 50 | BENCHMARK_CONTAINER(array, bitset, array_container_equal_bitset, DEFAULT_MAX_SIZE); |
| 51 | BENCHMARK_CONTAINER(run, bitset, run_container_equals_bitset, DEFAULT_MAX_SIZE); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | |