aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-05 12:46:18 +0000
committerlloyd <[email protected]>2008-09-05 12:46:18 +0000
commite292d9c1263fc74c26b26b9bd6f879ab25cc19ee (patch)
tree73953a1061223fc65e9236d232caf04bbc5a1aa4 /checks
parenta8973ceb0c0f70e67e30b1c36e4ed833bc158445 (diff)
Use the Timer class for all benchmarking
Diffstat (limited to 'checks')
-rw-r--r--checks/bench.cpp25
-rw-r--r--checks/bench.h19
-rw-r--r--checks/clock.cpp58
-rw-r--r--checks/common.h5
-rw-r--r--checks/pk.cpp76
-rw-r--r--checks/pk_bench.cpp15
-rw-r--r--checks/timer.cpp3
-rw-r--r--checks/timer.h6
-rw-r--r--checks/validate.cpp15
9 files changed, 91 insertions, 131 deletions
diff --git a/checks/bench.cpp b/checks/bench.cpp
index d3a9e06c4..f05bf8848 100644
--- a/checks/bench.cpp
+++ b/checks/bench.cpp
@@ -10,6 +10,7 @@ using Botan::byte;
using Botan::u64bit;
#include "common.h"
+#include "timer.h"
#include "bench.h"
/* Discard output to reduce overhead */
@@ -29,26 +30,24 @@ double bench_filter(std::string name, Botan::Filter* filter,
bool html, double seconds)
{
Botan::Pipe pipe(filter, new BitBucket);
- pipe.start_msg();
- static const u32bit BUFFERSIZE = 32*1024;
- byte buf[BUFFERSIZE];
+ pipe.start_msg();
- rng.randomize(buf, BUFFERSIZE);
+ byte buf[32 * 1024];
+ Timer timer(name, sizeof(buf));
- u32bit iterations = 0;
- u64bit start = get_clock(), clocks_used = 0;
- u64bit go_up_to = static_cast<u64bit>(seconds * get_ticks());
+ rng.randomize(buf, sizeof(buf));
- while(clocks_used < go_up_to)
+ while(timer.seconds() < seconds)
{
- iterations++;
- pipe.write(buf, BUFFERSIZE);
- clocks_used = get_clock() - start;
+ timer.start();
+ pipe.write(buf, sizeof(buf));
+ timer.stop();
}
- double bytes_per_sec = (static_cast<double>(iterations) * BUFFERSIZE) /
- (static_cast<double>(clocks_used) / get_ticks());
+ pipe.end_msg();
+
+ double bytes_per_sec = timer.events() / timer.seconds();
double mbytes_per_sec = bytes_per_sec / (1024.0 * 1024.0);
std::cout.setf(std::ios::fixed, std::ios::floatfield);
diff --git a/checks/bench.h b/checks/bench.h
index e101acdc2..f58ce3250 100644
--- a/checks/bench.h
+++ b/checks/bench.h
@@ -4,6 +4,25 @@
#include <botan/rng.h>
#include <string>
+#include <map>
+#include <set>
+#include "timer.h"
+
+#include <iostream>
+
+class Benchmark_Report
+ {
+ public:
+ void report(const std::string& name, Timer timer)
+ {
+ std::cout << name << " " << timer << "\n";
+ data[name].insert(timer);
+ }
+
+ private:
+ std::map<std::string, std::set<Timer> > data;
+ };
+
void benchmark(const std::string&, Botan::RandomNumberGenerator&,
bool html, double seconds);
diff --git a/checks/clock.cpp b/checks/clock.cpp
deleted file mode 100644
index 73f2c0e39..000000000
--- a/checks/clock.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <botan/botan.h>
-using namespace Botan;
-
-#include "common.h"
-#include <time.h>
-
-/*
- Using clock() or similiar is bad news when using a hardware-based Engine,
- as all the stuff is offloaded and we use zero CPU time, which makes the
- benchmarks and such take forever.
-*/
-
-#define USE_CLOCK 0
-#define USE_TIMES 0
-#define USE_POSIX_GETTIME 0
-#define USE_RDTSC 1
-
-/* If using USE_RDTSC, set to your CPU's Mhz */
-#define CPU_MHZ 2400
-
-#if USE_CLOCK
-
- u64bit get_clock() { return clock(); }
- u64bit get_ticks() { return CLOCKS_PER_SEC; }
-
-#elif USE_TIMES
-
- #include <sys/times.h>
- #include <unistd.h>
- u64bit get_clock() { return times(0); }
- u64bit get_ticks() { return sysconf(_SC_CLK_TCK); }
-
-#elif USE_POSIX_GETTIME
-
-u64bit get_clock()
- {
- struct timespec tv;
- clock_gettime(CLOCK_REALTIME, &tv);
-
- return (tv.tv_sec * 1000000000 + tv.tv_nsec) / 1000;
- }
-
-u64bit get_ticks() { return 1000000; }
-#elif USE_RDTSC
-
- u64bit get_clock()
- {
- u64bit rtc = 0;
- u32bit rtc_low = 0, rtc_high = 0;
- asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low));
- rtc = ((u64bit)rtc_high << 32) | rtc_low;
- return rtc / 1000;
- }
-
- u64bit get_ticks() { return CPU_MHZ * 1000; }
-#else
- #error "Must choose a timing method!"
-#endif
diff --git a/checks/common.h b/checks/common.h
index 06cb638ee..ac3daaf76 100644
--- a/checks/common.h
+++ b/checks/common.h
@@ -37,9 +37,6 @@ std::vector<std::string> parse(const std::string& line);
std::string hex_encode(const byte in[], u32bit len);
Botan::SecureVector<byte> decode_hex(const std::string&);
-Botan::u64bit get_clock();
-Botan::u64bit get_ticks();
-
Botan::Filter* lookup(const std::string& algname,
const std::vector<std::string>& params,
const std::string& section);
@@ -70,7 +67,7 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
return out;
}
- void randomize(byte out[], u32bit len) throw()
+ void randomize(byte out[], u32bit len)
{
for(u32bit j = 0; j != len; j++)
out[j] = random();
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 263f8e090..7a8f821fa 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -612,40 +612,48 @@ u32bit do_pk_validation_tests(const std::string& filename,
u32bit new_errors = 0;
- if(algorithm.find("DSA/") != std::string::npos)
- new_errors = validate_dsa_sig(algorithm, substr, rng);
- else if(algorithm.find("DSA_VA/") != std::string::npos)
- new_errors = validate_dsa_ver(algorithm, substr);
-
- else if(algorithm.find("RSAES_PKCS8/") != std::string::npos)
- new_errors = validate_rsa_enc_pkcs8(algorithm, substr, rng);
- else if(algorithm.find("RSAVA_X509/") != std::string::npos)
- new_errors = validate_rsa_ver_x509(algorithm, substr);
-
- else if(algorithm.find("RSAES/") != std::string::npos)
- new_errors = validate_rsa_enc(algorithm, substr, rng);
- else if(algorithm.find("RSASSA/") != std::string::npos)
- new_errors = validate_rsa_sig(algorithm, substr, rng);
- else if(algorithm.find("RSAVA/") != std::string::npos)
- new_errors = validate_rsa_ver(algorithm, substr);
- else if(algorithm.find("RWVA/") != std::string::npos)
- new_errors = validate_rw_ver(algorithm, substr);
- else if(algorithm.find("RW/") != std::string::npos)
- new_errors = validate_rw_sig(algorithm, substr, rng);
- else if(algorithm.find("NR/") != std::string::npos)
- new_errors = validate_nr_sig(algorithm, substr, rng);
- else if(algorithm.find("ElGamal/") != std::string::npos)
- new_errors = validate_elg_enc(algorithm, substr, rng);
- else if(algorithm.find("DH/") != std::string::npos)
- new_errors = validate_dh(algorithm, substr, rng);
- else if(algorithm.find("DLIES/") != std::string::npos)
- new_errors = validate_dlies(algorithm, substr, rng);
- else
- std::cout << "WARNING: Unknown PK algorithm "
- << algorithm << std::endl;
-
- alg_count++;
- errors += new_errors;
+ try
+ {
+
+ if(algorithm.find("DSA/") != std::string::npos)
+ new_errors = validate_dsa_sig(algorithm, substr, rng);
+ else if(algorithm.find("DSA_VA/") != std::string::npos)
+ new_errors = validate_dsa_ver(algorithm, substr);
+
+ else if(algorithm.find("RSAES_PKCS8/") != std::string::npos)
+ new_errors = validate_rsa_enc_pkcs8(algorithm, substr, rng);
+ else if(algorithm.find("RSAVA_X509/") != std::string::npos)
+ new_errors = validate_rsa_ver_x509(algorithm, substr);
+
+ else if(algorithm.find("RSAES/") != std::string::npos)
+ new_errors = validate_rsa_enc(algorithm, substr, rng);
+ else if(algorithm.find("RSASSA/") != std::string::npos)
+ new_errors = validate_rsa_sig(algorithm, substr, rng);
+ else if(algorithm.find("RSAVA/") != std::string::npos)
+ new_errors = validate_rsa_ver(algorithm, substr);
+ else if(algorithm.find("RWVA/") != std::string::npos)
+ new_errors = validate_rw_ver(algorithm, substr);
+ else if(algorithm.find("RW/") != std::string::npos)
+ new_errors = validate_rw_sig(algorithm, substr, rng);
+ else if(algorithm.find("NR/") != std::string::npos)
+ new_errors = validate_nr_sig(algorithm, substr, rng);
+ else if(algorithm.find("ElGamal/") != std::string::npos)
+ new_errors = validate_elg_enc(algorithm, substr, rng);
+ else if(algorithm.find("DH/") != std::string::npos)
+ new_errors = validate_dh(algorithm, substr, rng);
+ else if(algorithm.find("DLIES/") != std::string::npos)
+ new_errors = validate_dlies(algorithm, substr, rng);
+ else
+ std::cout << "WARNING: Unknown PK algorithm "
+ << algorithm << std::endl;
+
+ alg_count++;
+ errors += new_errors;
+ }
+ catch(std::exception& e)
+ {
+ std::cout << "Exception: " << e.what() << "\n";
+ }
if(new_errors)
std::cout << "ERROR: \"" << algorithm << "\" failed test #"
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index fb2414b0d..df1c6cde1 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -20,21 +20,6 @@ using namespace Botan;
#include <fstream>
#include <string>
#include <memory>
-#include <map>
-#include <set>
-
-class Benchmark_Report
- {
- public:
- void report(const std::string& name, Timer timer)
- {
- std::cout << name << " " << timer << "\n";
- data[name].insert(timer);
- }
-
- private:
- std::map<std::string, std::set<Timer> > data;
- };
namespace {
diff --git a/checks/timer.cpp b/checks/timer.cpp
index 4abd8a05f..0a5a05de2 100644
--- a/checks/timer.cpp
+++ b/checks/timer.cpp
@@ -9,7 +9,8 @@ u64bit Timer::get_clock()
return (tv.tv_sec * 1000000000ULL + tv.tv_nsec);
}
-Timer::Timer(const std::string& n) : name(n)
+Timer::Timer(const std::string& n, u32bit e_mul) :
+ name(n), event_mult(e_mul)
{
time_used = 0;
timer_start = 0;
diff --git a/checks/timer.h b/checks/timer.h
index 47bd7696e..4bdc08154 100644
--- a/checks/timer.h
+++ b/checks/timer.h
@@ -14,7 +14,7 @@ class Timer
public:
static u64bit get_clock();
- Timer(const std::string& name);
+ Timer(const std::string& name, u32bit event_mult = 1);
void start();
@@ -27,12 +27,12 @@ class Timer
double ms_per_event() { return milliseconds() / events(); }
double seconds_per_event() { return seconds() / events(); }
- u32bit events() const { return event_count; }
+ u32bit events() const { return event_count * event_mult; }
std::string get_name() const { return name; }
private:
std::string name;
u64bit time_used, timer_start;
- u32bit event_count;
+ u32bit event_count, event_mult;
};
inline bool operator<(const Timer& x, const Timer& y)
diff --git a/checks/validate.cpp b/checks/validate.cpp
index 5c3aca6d5..8fb225137 100644
--- a/checks/validate.cpp
+++ b/checks/validate.cpp
@@ -144,9 +144,18 @@ u32bit do_validation_tests(const std::string& filename,
}
counter++;
- bool failed = failed_test(algorithm, substr,
- is_extension, should_pass,
- section, last_missing, rng);
+ bool failed = true; // until proven otherwise
+
+ try
+ {
+ failed = failed_test(algorithm, substr,
+ is_extension, should_pass,
+ section, last_missing, rng);
+ }
+ catch(std::exception& e)
+ {
+ std::cout << "Exception: " << e.what() << "\n";
+ }
if(failed && should_pass)
{