diff options
author | lloyd <[email protected]> | 2009-12-16 22:54:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-16 22:54:39 +0000 |
commit | 1d595f8976483078c292e365bde3949c9de26332 (patch) | |
tree | 874f7cb1b2ba23405bc69330e6233eb567bf2ec4 /src/benchmark/benchmark.cpp | |
parent | f3f36611db8c3f6c67c818d454973a0165b0fcf2 (diff) | |
parent | 85b961ff87c1d6300451538c939c99a2ff74b505 (diff) |
propagate from branch 'net.randombit.botan' (head 22c82e10d78ad0e2cdaa56cb02f3d846ed0ead5e)
to branch 'net.randombit.botan.c++0x' (head 74dbf310b7fcc11f94a16cd63046219acd5d62bc)
Diffstat (limited to 'src/benchmark/benchmark.cpp')
-rw-r--r-- | src/benchmark/benchmark.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/src/benchmark/benchmark.cpp b/src/benchmark/benchmark.cpp index 69d3a40ec..5c812d732 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,16 @@ #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 BufferedComputation (hash or MAC) */ @@ -27,17 +30,22 @@ std::pair<u64bit, u64bit> bench_buf_comp(BufferedComputation* buf_comp, { u64bit reps = 0; - const u64bit start = get_nanoseconds_clock(); - u64bit nanoseconds_used = 0; + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + auto start = benchmark_clock::now(); - while(nanoseconds_used < nanoseconds_max) + while(time_used < max_time) { buf_comp->update(buf, buf_len); ++reps; - nanoseconds_used = get_nanoseconds_clock() - start; + time_used = benchmark_clock::now() - start; } - 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); } /** @@ -52,21 +60,25 @@ bench_block_cipher(BlockCipher* block_cipher, u64bit reps = 0; - const u64bit start = get_nanoseconds_clock(); - u64bit nanoseconds_used = 0; + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + auto start = benchmark_clock::now(); block_cipher->set_key(buf, block_cipher->MAXIMUM_KEYLENGTH); - while(nanoseconds_used < nanoseconds_max) + while(time_used < max_time) { block_cipher->encrypt_n(buf, buf, in_blocks); - ++reps; - nanoseconds_used = get_nanoseconds_clock() - start; + time_used = benchmark_clock::now() - start; } + 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); } /** @@ -79,19 +91,24 @@ bench_stream_cipher(StreamCipher* stream_cipher, { 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) + std::chrono::nanoseconds max_time(nanoseconds_max); + std::chrono::nanoseconds time_used(0); + + auto start = benchmark_clock::now(); + + while(time_used < max_time) { stream_cipher->cipher1(buf, buf_len); ++reps; - nanoseconds_used = get_nanoseconds_clock() - start; + time_used = benchmark_clock::now() - start; } - 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); } /** |