aboutsummaryrefslogtreecommitdiff
path: root/microbench
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2018-06-10 14:24:29 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2018-06-10 15:12:01 +0200
commite8f1b85d7441a09fa30f27c720e5dff4f2b1aa71 (patch)
tree766cb6124ad82d6c446b96bc51fe824a12ce401f /microbench
parent4ae87e3ce2dd1ff326af38561740bd62315b51ba (diff)
downloadcmix-e8f1b85d7441a09fa30f27c720e5dff4f2b1aa71.tar.gz
cmix-e8f1b85d7441a09fa30f27c720e5dff4f2b1aa71.tar.bz2
cmix-e8f1b85d7441a09fa30f27c720e5dff4f2b1aa71.zip
Adds a microbenchmark executable.HEADmaster
Diffstat (limited to 'microbench')
-rw-r--r--microbench/CMakeLists.txt18
-rw-r--r--microbench/microbench.cpp41
2 files changed, 59 insertions, 0 deletions
diff --git a/microbench/CMakeLists.txt b/microbench/CMakeLists.txt
new file mode 100644
index 0000000..a132ecf
--- /dev/null
+++ b/microbench/CMakeLists.txt
@@ -0,0 +1,18 @@
+
+find_package(Gcrypt REQUIRED)
+find_package(Boost COMPONENTS timer REQUIRED)
+
+add_executable(microbench
+ microbench.cpp
+)
+
+target_compile_options(scratchpad
+ PRIVATE ${Gcrypt_CFLAGS}
+)
+
+target_link_libraries(microbench
+ PRIVATE cmix
+ PRIVATE cmix-crypto
+ PRIVATE ${Gcrypt_LIBRARIES}
+ PRIVATE Boost::timer
+)
diff --git a/microbench/microbench.cpp b/microbench/microbench.cpp
new file mode 100644
index 0000000..0d21e5f
--- /dev/null
+++ b/microbench/microbench.cpp
@@ -0,0 +1,41 @@
+
+#include "api.h"
+
+#include <vector>
+#include <boost/timer/timer.hpp>
+#include <iostream>
+
+int main(int, char*[]) {
+ struct Api api = get_implementation();
+
+ size_t nr_test = 10000;
+
+ std::vector<GroupElement> elements(nr_test);
+
+ boost::timer::cpu_timer timer;
+ timer.start();
+
+ for(auto&& el : elements) {
+ el = api.get_group_element(true);
+ }
+
+ auto random_time = timer.elapsed().user;
+
+ for(size_t i = 0; i < nr_test; i++) {
+ elements[i] = api.combine(elements[i], elements[(i+1) % nr_test], true);
+ }
+
+ auto combine_time = timer.elapsed().user - random_time;
+
+ for(size_t i = 0; i < nr_test; i++) {
+ elements[i] = api.uncombine(elements[i], elements[(i+1) % nr_test], true);
+ }
+
+ auto uncombine_time = timer.elapsed().user - combine_time;
+ timer.stop();
+
+ std::cout << "Micro Benchmark:" << std::endl
+ << "Random:\t\t" << random_time / 1000000.0 << " ms" << std::endl
+ << "Combine:\t" << combine_time / 1000000.0 << " ms" << std::endl
+ << "Uncombine:\t" << uncombine_time / 1000000.0 << " ms" << std::endl;
+}