diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-12-15 11:03:20 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-12-15 11:03:20 -0800 |
| commit | 060870462606f82d3a9b0fe6aca87f8a5de8705e (patch) | |
| tree | 2001ea775c3a8b65c756d64fff88c664c609feb3 /selftest.cpp | |
| parent | cb8e7b4d5e3cb4c5b79ccb9f74c161182222daca (diff) | |
| download | infinitytier-060870462606f82d3a9b0fe6aca87f8a5de8705e.tar.gz infinitytier-060870462606f82d3a9b0fe6aca87f8a5de8705e.zip | |
Some micro-optimizations, including a memcpy that is faster than Linux for most distro/compiler versions.
Diffstat (limited to 'selftest.cpp')
| -rw-r--r-- | selftest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/selftest.cpp b/selftest.cpp index c3b8ce2f..86894564 100644 --- a/selftest.cpp +++ b/selftest.cpp @@ -660,6 +660,50 @@ static int testOther() std::cout << " " << InetAddress("").toString(buf); std::cout << std::endl; + std::cout << "[other] Benchmarking memcpy... "; std::cout.flush(); + { + unsigned char *bb = (unsigned char *)::malloc(1234567); + unsigned char *cc = (unsigned char *)::malloc(1234567); + for(unsigned int i=0;i<1234567;++i) + bb[i] = (unsigned char)i; + double bytes = 0.0; + uint64_t start = OSUtils::now(); + for(unsigned int i=0;i<20000;++i) { + ++bb[i]; + ++bb[i+1]; + memcpy(cc,bb,1234567); + bytes += 1234567.0; + } + if (cc[0] != bb[0]) + abort(); + uint64_t end = OSUtils::now(); + std::cout << ((bytes / 1048576.0) / ((long double)(end - start) / 1024.0)) << " MiB/second" << std::endl; + ::free((void *)bb); + ::free((void *)cc); + } + + std::cout << "[other] Benchmarking ZT_FAST_MEMCPY... "; std::cout.flush(); + { + unsigned char *bb = (unsigned char *)::malloc(1234567); + unsigned char *cc = (unsigned char *)::malloc(1234567); + for(unsigned int i=0;i<1234567;++i) + bb[i] = (unsigned char)i; + double bytes = 0.0; + uint64_t start = OSUtils::now(); + for(unsigned int i=0;i<20000;++i) { + ++bb[0]; + ++bb[1234566]; + ZT_FAST_MEMCPY(cc,bb,1234567); + bytes += 1234567.0; + } + if (cc[0] != bb[0]) + abort(); + uint64_t end = OSUtils::now(); + std::cout << ((bytes / 1048576.0) / ((long double)(end - start) / 1024.0)) << " MiB/second" << std::endl; + ::free((void *)bb); + ::free((void *)cc); + } + #if 0 std::cout << "[other] Testing Hashtable... "; std::cout.flush(); { |
