Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add benchmark for sparse cases #533

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}