diff options
author | lloyd <[email protected]> | 2012-02-20 17:09:46 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-02-20 17:09:46 +0000 |
commit | 8c2dc1a6c3bf352a56622d569dc855ca8d6ab5e0 (patch) | |
tree | 6f50627e2e73c2b1fc1295dde8b19c4f169de46d /src/benchmark | |
parent | 24c1546324995da70c51137ad138c3bb997a37b9 (diff) | |
parent | e943fc67962b6e4dc2c7c64707dc2cf062728520 (diff) |
propagate from branch 'net.randombit.botan.tls-state-machine' (head 0ceb9cde62a2b3614901ae85a53546d9fc641326)
to branch 'net.randombit.botan.cxx11' (head 777e65950ef3706a82e5df20dcca7fcc999ca533)
Diffstat (limited to 'src/benchmark')
-rw-r--r-- | src/benchmark/benchmark.cpp | 61 | ||||
-rw-r--r-- | src/benchmark/benchmark.h | 3 |
2 files changed, 40 insertions, 24 deletions
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index dbccd45c1..cb5d8bb41 100644 --- a/src/benchmark/benchmark.cpp +++ b/src/benchmark/benchmark.cpp @@ -1,6 +1,6 @@ /* * Runtime benchmarking -* (C) 2008 Jack Lloyd +* (C) 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -11,13 +11,15 @@ #include <botan/stream_cipher.h> #include <botan/hash.h> #include <botan/mac.h> -#include <botan/time.h> #include <memory> - +#include <vector> +#include <chrono> namespace Botan { namespace { +typedef std::chrono::high_resolution_clock benchmark_clock; + /** * Benchmark Buffered_Computation (hash or MAC) */ @@ -26,18 +28,23 @@ std::pair<u64bit, u64bit> bench_buf_comp(Buffered_Computation* buf_comp, const byte buf[], size_t buf_len) { u64bit reps = 0; - u64bit nanoseconds_used = 0; - while(nanoseconds_used < nanoseconds_max) + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + while(time_used < max_time) { - const u64bit start = get_nanoseconds_clock(); + auto start = benchmark_clock::now(); buf_comp->update(buf, buf_len); - nanoseconds_used += get_nanoseconds_clock() - start; + time_used += benchmark_clock::now() - start; ++reps; } - return std::make_pair(reps * buf_len, nanoseconds_used); + u64bit ns_taken = + std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count(); + + return std::make_pair(reps * buf_len, ns_taken); } /** @@ -51,21 +58,26 @@ bench_block_cipher(BlockCipher* block_cipher, const size_t in_blocks = buf_len / block_cipher->block_size(); u64bit reps = 0; - u64bit nanoseconds_used = 0; + + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); block_cipher->set_key(buf, block_cipher->maximum_keylength()); - while(nanoseconds_used < nanoseconds_max) + while(time_used < max_time) { - const u64bit start = get_nanoseconds_clock(); + auto start = benchmark_clock::now(); block_cipher->encrypt_n(buf, buf, in_blocks); - nanoseconds_used += get_nanoseconds_clock() - start; + time_used += benchmark_clock::now() - start; ++reps; } + u64bit ns_taken = + std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count(); + return std::make_pair(reps * in_blocks * block_cipher->block_size(), - nanoseconds_used); + ns_taken); } /** @@ -77,20 +89,25 @@ bench_stream_cipher(StreamCipher* stream_cipher, byte buf[], size_t buf_len) { u64bit reps = 0; - u64bit nanoseconds_used = 0; stream_cipher->set_key(buf, stream_cipher->maximum_keylength()); - while(nanoseconds_used < nanoseconds_max) + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + while(time_used < max_time) { - const u64bit start = get_nanoseconds_clock(); + auto start = benchmark_clock::now(); stream_cipher->cipher1(buf, buf_len); - nanoseconds_used += get_nanoseconds_clock() - start; + time_used += benchmark_clock::now() - start; ++reps; } - return std::make_pair(reps * buf_len, nanoseconds_used); + u64bit ns_taken = + std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count(); + + return std::make_pair(reps * buf_len, ns_taken); } /** @@ -146,7 +163,7 @@ algorithm_benchmark(const std::string& name, if(const BlockCipher* proto = af.prototype_block_cipher(name, provider)) { - std::auto_ptr<BlockCipher> block_cipher(proto->clone()); + std::unique_ptr<BlockCipher> block_cipher(proto->clone()); results = bench_block_cipher(block_cipher.get(), ns_per_provider, &buf[0], buf.size()); @@ -154,7 +171,7 @@ algorithm_benchmark(const std::string& name, else if(const StreamCipher* proto = af.prototype_stream_cipher(name, provider)) { - std::auto_ptr<StreamCipher> stream_cipher(proto->clone()); + std::unique_ptr<StreamCipher> stream_cipher(proto->clone()); results = bench_stream_cipher(stream_cipher.get(), ns_per_provider, &buf[0], buf.size()); @@ -162,14 +179,14 @@ algorithm_benchmark(const std::string& name, else if(const HashFunction* proto = af.prototype_hash_function(name, provider)) { - std::auto_ptr<HashFunction> hash(proto->clone()); + std::unique_ptr<HashFunction> hash(proto->clone()); 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()); + std::unique_ptr<MessageAuthenticationCode> mac(proto->clone()); results = bench_mac(mac.get(), ns_per_provider, &buf[0], buf.size()); } diff --git a/src/benchmark/benchmark.h b/src/benchmark/benchmark.h index c47fdc166..f3e43bd06 100644 --- a/src/benchmark/benchmark.h +++ b/src/benchmark/benchmark.h @@ -1,6 +1,6 @@ /* * Runtime benchmarking -* (C) 2008 Jack Lloyd +* (C) 2008-2009 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -12,7 +12,6 @@ #include <botan/rng.h> #include <map> #include <string> - namespace Botan { /** |