Skip to content

Instantly share code, notes, and snippets.

@Adenilson
Created February 21, 2017 20:56
Show Gist options
  • Save Adenilson/f1e175d364bdad2753fde34361e5e650 to your computer and use it in GitHub Desktop.
Save Adenilson/f1e175d364bdad2753fde34361e5e650 to your computer and use it in GitHub Desktop.
void timing()
{
unsigned int len = 4096 * 4096;
unsigned char *buf = new unsigned char[len];
srand(12345);
for (size_t i = 0; i < len; i++) {
buf[i] = (uint8_t)(rand() >> 8);
}
auto current_timestamp = []() -> long long {
struct timeval te;
gettimeofday(&te, NULL);
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000;
return milliseconds;
};
auto benchmark = [&](std::function<unsigned long(unsigned long, unsigned char *, unsigned int)> callback,
const std::string &name,
const size_t runs) -> long long{
long long start, end;
unsigned long adler = 0;
start = current_timestamp();
for (size_t i = 0; i < runs; ++i) {
adler = callback(adler, buf, len);
}
end = current_timestamp();
std::cout << "### Function " << name
<< " took " << end - start << " ms." << std::endl;
return end - start;
};
// A first execution to prime caches and warm up the CPU.
unsigned long tmp = 0;
tmp = adler32_z(tmp, buf, len);
benchmark(adler32_z, "zlib reference", 30);
benchmark(NEON_adler32, "neonized", 30);
delete [] buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment