Skip to content

Commit

Permalink
add benchmark for sparse cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stdpain committed Dec 28, 2023
1 parent 13407ae commit 91303a2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ if(NOT WIN32)
add_c_benchmark(add_benchmark)
target_link_libraries(add_benchmark m)
add_c_benchmark(intersect_range_benchmark)
target_link_libraries(add_benchmark m)
add_c_benchmark(frozen_benchmark)
add_c_benchmark(containsmulti_benchmark)
add_cpp_benchmark(fastunion_benchmark)
add_cpp_benchmark(sparse_cases_benchmark)
endif()
add_c_benchmark(bitset_container_benchmark)
add_c_benchmark(array_container_benchmark)
Expand Down
52 changes: 52 additions & 0 deletions benchmarks/sparse_cases_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <roaring/roaring.h>

#include <iostream>
#include <random>
#include <roaring64map.hh>

#include "benchmark.h"

// the same key will add to the same bitmap
static std::default_random_engine e;

void run_bench(size_t batch_size, int loop_count, size_t max) {
using namespace roaring;
using roaring::Roaring;
std::uniform_int_distribution<uint64_t> dist(0, max);
uint64_t cycles_start, cycles_final;
RDTSC_START(cycles_start);
for (int j = 0; j < loop_count ; ++j) {
Roaring64Map bitmap_64;
for (size_t i = 0; i < batch_size; i++) {
bitmap_64.add(dist(e));
}
}

RDTSC_FINAL(cycles_final);
std::cout << "batch_size=" << batch_size << ", max=" << max << " costs:"
<< (cycles_final - cycles_start) * 1.0 / batch_size / loop_count
<< std::endl;
}

int main(int argc, char* argv[]) {
(void)argc;
(void)argv;

run_bench(100, 10, 100);
run_bench(100, 10, 1000);
run_bench(100, 10, 1000000);
run_bench(100, 10, 100000000);
run_bench(100, 10, 10000000000);

run_bench(100000, 10, 1000);
run_bench(100000, 10, 100000);
run_bench(100000, 10, 1000000000);
run_bench(100000, 10, 100000000000);

run_bench(100000000, 1, 100000000);
run_bench(100000000, 1, 500000000);
run_bench(100000000, 1, 5000000000);


return 0;
}

0 comments on commit 91303a2

Please sign in to comment.