7#include "../include/minisketch.h"
16int main(
int argc,
char** argv) {
17 if (argc < 1 || argc > 4) {
18 printf(
"Usage: %s [syndromes=150] [errors=syndromes] [iters=10]\n", argv[0]);
21 int syndromes = argc > 1 ? strtoul(argv[1], NULL, 10) : 150;
22 int errors = argc > 2 ? strtoul(argv[2], NULL, 10) : syndromes;
23 int iters = argc > 3 ? strtoul(argv[3], NULL, 10) : 10;
24 if (syndromes < 0 || syndromes > 1000000) {
25 printf(
"Number of syndromes (%i) out of range 0..1000000\n", syndromes);
29 printf(
"Number of errors (%i) is negative(%i)\n", errors, syndromes);
32 if (iters < 0 || iters > 1000000000) {
33 printf(
"Number of iterations (%i) out of range 0..1000000000\n", iters);
37 for (
int bits = 2; bits <= 64; ++bits) {
38 if (errors > pow(2.0, bits - 1))
continue;
40 printf(
"recover[ms]\t% 3i\t", bits);
41 for (uint32_t impl = 0; impl <= max_impl; ++impl) {
42 std::vector<minisketch*> states;
43 std::vector<uint64_t> roots(2 * syndromes);
44 std::random_device rng;
45 std::uniform_int_distribution<uint64_t> dist(1, (uint64_t(1) << bits) - 1);
47 std::vector<double> benches;
48 benches.reserve(iters);
49 for (
int i = 0; i < iters; ++i) {
51 if (!states[i])
break;
52 std::set<uint64_t> done;
53 for (
int j = 0; j < errors; ++j) {
57 }
while (done.count(r));
65 for (
auto& state : states) {
66 auto start = std::chrono::steady_clock::now();
68 auto stop = std::chrono::steady_clock::now();
69 std::chrono::duration<double> dur(
stop - start);
70 benches.push_back(dur.count());
72 std::sort(benches.begin(), benches.end());
73 printf(
"% 10.5f\t", benches[0] * 1000.0);
75 for (
auto& state : states) {
80 printf(
"create[ns]\t% 3i\t", bits);
81 for (uint32_t impl = 0; impl <= max_impl; ++impl) {
82 std::vector<minisketch*> states;
83 std::random_device rng;
84 std::uniform_int_distribution<uint64_t> dist;
85 std::vector<uint64_t>
data;
86 data.resize(errors * 10);
88 std::vector<double> benches;
89 benches.reserve(iters);
90 for (
int i = 0; i < iters; ++i) {
93 for (
size_t i = 0; i <
data.size(); ++i) {
99 for (
auto& state : states) {
100 auto start = std::chrono::steady_clock::now();
101 for (
auto val :
data) {
104 auto stop = std::chrono::steady_clock::now();
105 std::chrono::duration<double> dur(
stop - start);
106 benches.push_back(dur.count());
108 std::sort(benches.begin(), benches.end());
109 printf(
"% 10.5f\t", benches[0] * 1000000000.0 /
data.size() / syndromes);
111 for (
auto& state : states) {
int main(int argc, char **argv)
MINISKETCH_API ssize_t minisketch_decode(const minisketch *sketch, size_t max_elements, uint64_t *output)
Decode a sketch.
MINISKETCH_API int minisketch_bits_supported(uint32_t bits)
Determine whether support for elements of bits bits was compiled in.
MINISKETCH_API minisketch * minisketch_create(uint32_t bits, uint32_t implementation, size_t capacity)
Construct a sketch for a given element size, implementation and capacity.
MINISKETCH_API uint32_t minisketch_implementation_max(void)
Determine the maximum number of implementations available.
MINISKETCH_API void minisketch_add_uint64(minisketch *sketch, uint64_t element)
Add an element to a sketch.
MINISKETCH_API void minisketch_destroy(minisketch *sketch)
Destroy a sketch.