2017-01-27 12:05:45 +00:00
|
|
|
// bench.h - originally written and placed in the public domain by Wei Dai
|
2017-02-21 07:03:29 +00:00
|
|
|
// CryptoPP::Test namespace added by JW in February 2017
|
2015-11-18 20:32:28 +00:00
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
#ifndef CRYPTOPP_BENCH_H
|
|
|
|
#define CRYPTOPP_BENCH_H
|
|
|
|
|
|
|
|
#include "cryptlib.h"
|
|
|
|
|
2017-03-08 21:59:24 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <cmath>
|
|
|
|
#include <ctime>
|
|
|
|
|
2017-02-21 07:03:29 +00:00
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
NAMESPACE_BEGIN(Test)
|
|
|
|
|
2017-05-20 03:29:59 +00:00
|
|
|
// More granular control over benchmarks
|
|
|
|
enum TestClass {
|
2017-08-22 09:10:25 +00:00
|
|
|
UnkeyedRNG=(1<<0),UnkeyedHash=(1<<1),UnkeyedOther=(1<<2),
|
|
|
|
SharedKeyMAC=(1<<3),SharedKeyStream=(1<<4),SharedKeyBlock=(1<<5),SharedKeyOther=(1<<6),
|
|
|
|
PublicKeyAgreement=(1<<7),PublicKeyEncryption=(1<<8),PublicKeySignature=(1<<9),PublicKeyOther=(1<<10),
|
2017-07-24 03:52:34 +00:00
|
|
|
Unkeyed=UnkeyedRNG|UnkeyedHash|UnkeyedOther,
|
2017-05-20 03:29:59 +00:00
|
|
|
SharedKey=SharedKeyMAC|SharedKeyStream|SharedKeyBlock|SharedKeyOther,
|
|
|
|
PublicKey=PublicKeyAgreement|PublicKeyEncryption|PublicKeySignature|PublicKeyOther,
|
2017-08-22 09:10:25 +00:00
|
|
|
All=Unkeyed|SharedKey|PublicKey,
|
|
|
|
TestFirst=(0), TestLast=(1<<11)
|
2017-05-20 03:29:59 +00:00
|
|
|
};
|
2017-04-14 01:45:21 +00:00
|
|
|
|
2017-03-08 21:59:24 +00:00
|
|
|
extern const double CLOCK_TICKS_PER_SECOND;
|
|
|
|
extern double g_allocatedTime;
|
|
|
|
extern double g_hertz;
|
|
|
|
extern double g_logTotal;
|
|
|
|
extern unsigned int g_logCount;
|
|
|
|
extern const byte defaultKey[];
|
|
|
|
|
|
|
|
// Test book keeping
|
|
|
|
extern time_t g_testBegin;
|
|
|
|
extern time_t g_testEnd;
|
|
|
|
|
2018-12-08 13:08:08 +00:00
|
|
|
// Benchmark command handler
|
2017-05-20 03:29:59 +00:00
|
|
|
void BenchmarkWithCommand(int argc, const char* const argv[]);
|
2017-03-08 21:59:24 +00:00
|
|
|
// Top level, prints preamble and postamble
|
2017-04-14 01:45:21 +00:00
|
|
|
void Benchmark(Test::TestClass suites, double t, double hertz);
|
2017-03-08 21:59:24 +00:00
|
|
|
// Unkeyed systems
|
|
|
|
void Benchmark1(double t, double hertz);
|
|
|
|
// Shared key systems
|
|
|
|
void Benchmark2(double t, double hertz);
|
|
|
|
// Public key systems
|
|
|
|
void Benchmark3(double t, double hertz);
|
|
|
|
|
2018-07-27 18:13:58 +00:00
|
|
|
// These are defined in bench1.cpp
|
|
|
|
extern void OutputResultKeying(double iterations, double timeTaken);
|
|
|
|
extern void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken);
|
|
|
|
extern void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken);
|
|
|
|
|
|
|
|
// These are defined in bench1.cpp
|
|
|
|
extern void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal);
|
|
|
|
extern void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal);
|
|
|
|
extern void BenchMark(const char *name, HashTransformation &ht, double timeTotal);
|
|
|
|
extern void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal);
|
|
|
|
|
|
|
|
// These are defined in bench2.cpp
|
|
|
|
extern void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs ¶ms);
|
|
|
|
extern void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal);
|
2015-11-05 06:59:46 +00:00
|
|
|
|
2017-02-21 07:03:29 +00:00
|
|
|
NAMESPACE_END // Test
|
|
|
|
NAMESPACE_END // CryptoPP
|
|
|
|
|
2015-11-05 06:59:46 +00:00
|
|
|
#endif
|