diff options
author | lloyd <[email protected]> | 2009-12-01 12:00:48 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-01 12:00:48 +0000 |
commit | 874dbb8323dd4d7eff3ff16cff0cfafc16ddbfa7 (patch) | |
tree | bc3a84c43c5924119972f24da3af89317694f0cb /src/benchmark/benchmark.cpp | |
parent | 78f5726220b637cd8ae117bbcf8ff8d6c8dfeaed (diff) |
Consolidate the non-canonical epoch timers, like cpuid and Win32's
QueryPerformanceCounter, into an entropy source hres_timer. Its
results, if any, do not count as contributing entropy to the poll.
Convert the other (monotonic/fixed epoch) timers to a single function
get_nanoseconds_clock(), living in time.h, which statically chooses
the 'best' timer type (clock_gettime, gettimeofday, std::clock, in
that order depending on what is available). Add feature test macros
for clock_gettime and gettimeofday.
Remove the Timer class and timer.h. Remove the Timer& argument to the
algorithm benchmark function.
Diffstat (limited to 'src/benchmark/benchmark.cpp')
-rw-r--r-- | src/benchmark/benchmark.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 41c9cd10c..69d3a40ec 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -11,6 +11,7 @@ #include <botan/stream_cipher.h> #include <botan/hash.h> #include <botan/mac.h> +#include <botan/time.h> #include <memory> namespace Botan { @@ -21,19 +22,19 @@ namespace { * Benchmark BufferedComputation (hash or MAC) */ std::pair<u64bit, u64bit> bench_buf_comp(BufferedComputation* buf_comp, - Timer& timer, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; u64bit reps = 0; + const u64bit start = get_nanoseconds_clock(); + u64bit nanoseconds_used = 0; + while(nanoseconds_used < nanoseconds_max) { buf_comp->update(buf, buf_len); ++reps; - nanoseconds_used = timer.clock() - start; + nanoseconds_used = get_nanoseconds_clock() - start; } return std::make_pair(reps * buf_len, nanoseconds_used); @@ -44,15 +45,15 @@ std::pair<u64bit, u64bit> bench_buf_comp(BufferedComputation* buf_comp, */ std::pair<u64bit, u64bit> bench_block_cipher(BlockCipher* block_cipher, - Timer& timer, u64bit nanoseconds_max, byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; + const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE; + u64bit reps = 0; - const u32bit in_blocks = buf_len / block_cipher->BLOCK_SIZE; + const u64bit start = get_nanoseconds_clock(); + u64bit nanoseconds_used = 0; block_cipher->set_key(buf, block_cipher->MAXIMUM_KEYLENGTH); @@ -61,7 +62,7 @@ bench_block_cipher(BlockCipher* block_cipher, block_cipher->encrypt_n(buf, buf, in_blocks); ++reps; - nanoseconds_used = timer.clock() - start; + nanoseconds_used = get_nanoseconds_clock() - start; } return std::make_pair(reps * in_blocks * block_cipher->BLOCK_SIZE, @@ -73,21 +74,21 @@ bench_block_cipher(BlockCipher* block_cipher, */ std::pair<u64bit, u64bit> bench_stream_cipher(StreamCipher* stream_cipher, - Timer& timer, u64bit nanoseconds_max, byte buf[], u32bit buf_len) { - const u64bit start = timer.clock(); - u64bit nanoseconds_used = 0; u64bit reps = 0; + const u64bit start = get_nanoseconds_clock(); + u64bit nanoseconds_used = 0; + stream_cipher->set_key(buf, stream_cipher->MAXIMUM_KEYLENGTH); while(nanoseconds_used < nanoseconds_max) { stream_cipher->cipher1(buf, buf_len); ++reps; - nanoseconds_used = timer.clock() - start; + nanoseconds_used = get_nanoseconds_clock() - start; } return std::make_pair(reps * buf_len, nanoseconds_used); @@ -97,11 +98,11 @@ bench_stream_cipher(StreamCipher* stream_cipher, * Benchmark hash */ std::pair<u64bit, u64bit> -bench_hash(HashFunction* hash, Timer& timer, +bench_hash(HashFunction* hash, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { - return bench_buf_comp(hash, timer, nanoseconds_max, buf, buf_len); + return bench_buf_comp(hash, nanoseconds_max, buf, buf_len); } /** @@ -109,12 +110,11 @@ bench_hash(HashFunction* hash, Timer& timer, */ std::pair<u64bit, u64bit> bench_mac(MessageAuthenticationCode* mac, - Timer& timer, u64bit nanoseconds_max, const byte buf[], u32bit buf_len) { mac->set_key(buf, mac->MAXIMUM_KEYLENGTH); - return bench_buf_comp(mac, timer, nanoseconds_max, buf, buf_len); + return bench_buf_comp(mac, nanoseconds_max, buf, buf_len); } } @@ -122,7 +122,6 @@ bench_mac(MessageAuthenticationCode* mac, std::map<std::string, double> algorithm_benchmark(const std::string& name, u32bit milliseconds, - Timer& timer, RandomNumberGenerator& rng, Algorithm_Factory& af) { @@ -148,7 +147,7 @@ algorithm_benchmark(const std::string& name, af.prototype_block_cipher(name, provider)) { std::auto_ptr<BlockCipher> block_cipher(proto->clone()); - results = bench_block_cipher(block_cipher.get(), timer, + results = bench_block_cipher(block_cipher.get(), ns_per_provider, &buf[0], buf.size()); } @@ -156,7 +155,7 @@ algorithm_benchmark(const std::string& name, af.prototype_stream_cipher(name, provider)) { std::auto_ptr<StreamCipher> stream_cipher(proto->clone()); - results = bench_stream_cipher(stream_cipher.get(), timer, + results = bench_stream_cipher(stream_cipher.get(), ns_per_provider, &buf[0], buf.size()); } @@ -164,14 +163,14 @@ algorithm_benchmark(const std::string& name, af.prototype_hash_function(name, provider)) { std::auto_ptr<HashFunction> hash(proto->clone()); - results = bench_hash(hash.get(), timer, ns_per_provider, + results = bench_hash(hash.get(), ns_per_provider, &buf[0], buf.size()); } else if(const MessageAuthenticationCode* proto = af.prototype_mac(name, provider)) { std::auto_ptr<MessageAuthenticationCode> mac(proto->clone()); - results = bench_mac(mac.get(), timer, ns_per_provider, + results = bench_mac(mac.get(), ns_per_provider, &buf[0], buf.size()); } |