32 auto seed = system_clock::now().time_since_epoch().count();
33 std::default_random_engine generator(seed);
34 std::uniform_int_distribution<uint8_t> dist;
36 for(
auto & it : buffer)
41 int main(
int argc,
char ** argv)
45 std::cout <<
"\n Missing number of bytes to test\n";
46 std::cout <<
"\n usage: bphash_benchmark nbytes\n\n";
50 size_t nbytes =
static_cast<size_t>(atol(argv[1]));
52 std::vector<uint8_t> testdata(nbytes);
55 const void * testdata_ptr = testdata.data();
56 const size_t testdata_size = testdata.size();
58 std::cout <<
"\nTesting hashing of " << nbytes <<
" bytes\n";
59 std::cout <<
"Times in microseconds\n";
61 high_resolution_clock timer_clock;
64 const double conv_fac = 1.0e6/(1024.0 * 1024.0 * 1024.0);
67 auto time0 = timer_clock.now();
69 mh32.
update(testdata_ptr, testdata_size);
71 auto time1 = timer_clock.now();
72 auto elapsed = duration_cast<microseconds>(time1-time0).count();
73 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
74 std::cout <<
" 32-bit x32 hash: " << elapsed
75 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
79 auto time0 = timer_clock.now();
81 mh32.
update(testdata_ptr, testdata_size);
83 auto time1 = timer_clock.now();
84 auto elapsed = duration_cast<microseconds>(time1-time0).count();
85 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
86 std::cout <<
" 32-bit x64 hash: " << elapsed
87 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
91 auto time0 = timer_clock.now();
93 mh64.
update(testdata_ptr, testdata_size);
95 auto time1 = timer_clock.now();
96 auto elapsed = duration_cast<microseconds>(time1-time0).count();
97 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
98 std::cout <<
" 64-bit x64 hash: " << elapsed
99 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
103 auto time0 = timer_clock.now();
105 mh128.
update(testdata_ptr, testdata_size);
107 auto time1 = timer_clock.now();
108 auto elapsed = duration_cast<microseconds>(time1-time0).count();
109 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
110 std::cout <<
" 128-bit x64 hash: " << elapsed
111 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
114 std::cout <<
"\nHashing of vector via make_hash\n";
117 auto time0 = timer_clock.now();
119 auto time1 = timer_clock.now();
120 auto elapsed = duration_cast<microseconds>(time1-time0).count();
121 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
122 std::cout <<
" 32-bit x32 hash: " << elapsed
123 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
127 auto time0 = timer_clock.now();
129 auto time1 = timer_clock.now();
130 auto elapsed = duration_cast<microseconds>(time1-time0).count();
131 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
132 std::cout <<
" 32-bit x64 hash: " << elapsed
133 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
137 auto time0 = timer_clock.now();
139 auto time1 = timer_clock.now();
140 auto elapsed = duration_cast<microseconds>(time1-time0).count();
141 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
142 std::cout <<
" 64-bit x64 hash: " << elapsed
143 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
147 auto time0 = timer_clock.now();
149 auto time1 = timer_clock.now();
150 auto elapsed = duration_cast<microseconds>(time1-time0).count();
151 double rate =
static_cast<double>(nbytes)/static_cast<double>(elapsed);
152 std::cout <<
" 128-bit x64 hash: " << elapsed
153 <<
" ( " << conv_fac*rate <<
" GiB/sec)\n";
Implementation of MurmurHash3 32-bit x64 hash.
virtual void update(void const *data, size_t nbytes)
Add some data to the hash.
Default 32-bit hash for x86-64.
int main(int argc, char **argv)
Implementation of MurmurHash3 64-bit x64 hash.
Default 64-bit hash for x86-64.
Default 32-bit hash for x32.
Default 128-bit hash for x86-64.
A class that hashes objects (header)
MurmurHash3 32-bit x32 hash (header)
virtual HashValue finalize(void)
Finish hashing and report the hash.
static void random_fill(std::vector< uint8_t > &buffer)
HashValue make_hash(HashType type, const Targs &...objs)
Convenience function for hashing objects in a single function call.
std::vector< uint8_t > HashValue
Stores the value of a hash.
MurmurHash3 128-bit x64 hash (header)
virtual HashValue finalize(void)
Finish hashing and report the hash.
MurmurHash3 32-bit x64 hash (header)
virtual HashValue finalize(void)
Finish hashing and report the hash.
Implementation of MurmurHash3 32-bit x32 hash.
Implementation of MurmurHash3 128-bit x64 hash.
virtual void update(void const *data, size_t nbytes)
Add some data to the hash.
MurmurHash3 64-bit x64 hash (header)
virtual HashValue finalize(void)
Finish hashing and report the hash.