aboutsummaryrefslogtreecommitdiffstats
path: root/src/benchmark/benchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmark/benchmark.cpp')
-rw-r--r--src/benchmark/benchmark.cpp55
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);
}
/**