aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-02-02 17:18:34 +0000
committerlloyd <[email protected]>2014-02-02 17:18:34 +0000
commitca231638e37c2728abbcfbce09614bef37604cb3 (patch)
treebd50907cb7d67c7dc775a4605f48b0407d748c05 /src/cmd
parentd93eb71f1c2f1a74fbdde5e82d7f7c5e0a0ee4f0 (diff)
Inline time_op and avoid nonce recalc with every AEAD call
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/speed/speed.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/cmd/speed/speed.cpp b/src/cmd/speed/speed.cpp
index f265045fb..381cc9d83 100644
--- a/src/cmd/speed/speed.cpp
+++ b/src/cmd/speed/speed.cpp
@@ -126,20 +126,35 @@ void time_transform(std::unique_ptr<Transformation> tf,
if(!tf)
return;
+ const std::chrono::seconds runtime(2);
+
for(size_t buf_size : { 16, 64, 256, 1024, 8192 })
{
secure_vector<byte> buffer(buf_size);
- double res = time_op(std::chrono::seconds(1),
- [&tf,&buffer,buf_size,&rng]{
- tf->start_vec(rng.random_vec(tf->default_nonce_length()));
- tf->finish(buffer);
- buffer.resize(buf_size);
- });
+ std::chrono::nanoseconds time_used(0);
+
+ tf->start_vec(rng.random_vec(tf->default_nonce_length()));
+
+ auto start = std::chrono::high_resolution_clock::now();
+
+ secure_vector<byte> buf(buf_size);
+ size_t reps = 0;
+ while(time_used < runtime)
+ {
+ tf->update(buf);
+ buf.resize(buf_size);
+ ++reps;
+ time_used = std::chrono::high_resolution_clock::now() - start;
+ }
+
+ const u64bit nsec_used = std::chrono::duration_cast<std::chrono::nanoseconds>(time_used).count();
+
+ const double seconds_used = static_cast<double>(nsec_used) / 1000000000;
- const double Mbytes = (res * buf_size) / 1024 / 1024;
+ const double Mbps = ((reps / seconds_used) * buf_size) / 1024 / 1024;
- std::cout << tf->name() << " " << std::setprecision(4) << Mbytes
+ std::cout << tf->name() << " " << std::setprecision(4) << Mbps
<< " MiB / sec with " << buf_size << " byte blocks\n";
}
}