bench.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // bench.h - originally written and placed in the public domain by Wei Dai
  2. // CryptoPP::Test namespace added by JW in February 2017
  3. #ifndef CRYPTOPP_BENCH_H
  4. #define CRYPTOPP_BENCH_H
  5. #include "cryptlib.h"
  6. #include <iostream>
  7. #include <iomanip>
  8. #include <cmath>
  9. #include <ctime>
  10. NAMESPACE_BEGIN(CryptoPP)
  11. NAMESPACE_BEGIN(Test)
  12. // More granular control over benchmarks
  13. enum TestClass {
  14. /// \brief Random number generators
  15. UnkeyedRNG=(1<<0),
  16. /// \brief Message digests
  17. UnkeyedHash=(1<<1),
  18. /// \brief Other unkeyed algorithms
  19. UnkeyedOther=(1<<2),
  20. /// \brief Message authentication codes
  21. SharedKeyMAC=(1<<3),
  22. /// \brief Stream ciphers
  23. SharedKeyStream=(1<<4),
  24. /// \brief Block ciphers ciphers
  25. SharedKeyBlock=(1<<5),
  26. /// \brief Other shared key algorithms
  27. SharedKeyOther=(1<<6),
  28. /// \brief Key agreement algorithms over integers
  29. PublicKeyAgreement=(1<<7),
  30. /// \brief Encryption algorithms over integers
  31. PublicKeyEncryption=(1<<8),
  32. /// \brief Signature algorithms over integers
  33. PublicKeySignature=(1<<9),
  34. /// \brief Other public key algorithms over integers
  35. PublicKeyOther=(1<<10),
  36. /// \brief Key agreement algorithms over EC
  37. PublicKeyAgreementEC=(1<<11),
  38. /// \brief Encryption algorithms over EC
  39. PublicKeyEncryptionEC=(1<<12),
  40. /// \brief Signature algorithms over EC
  41. PublicKeySignatureEC=(1<<13),
  42. /// \brief Other public key algorithms over EC
  43. PublicKeyOtherEC=(1<<14),
  44. Unkeyed=UnkeyedRNG|UnkeyedHash|UnkeyedOther,
  45. SharedKey=SharedKeyMAC|SharedKeyStream|SharedKeyBlock|SharedKeyOther,
  46. PublicKey=PublicKeyAgreement|PublicKeyEncryption|PublicKeySignature|PublicKeyOther,
  47. PublicKeyEC=PublicKeyAgreementEC|PublicKeyEncryptionEC|PublicKeySignatureEC|PublicKeyOtherEC,
  48. All=Unkeyed|SharedKey|PublicKey|PublicKeyEC,
  49. TestFirst=(0), TestLast=(1<<15)
  50. };
  51. extern const double CLOCK_TICKS_PER_SECOND;
  52. extern double g_allocatedTime;
  53. extern double g_hertz;
  54. extern double g_logTotal;
  55. extern unsigned int g_logCount;
  56. extern const byte defaultKey[];
  57. // Test book keeping
  58. extern time_t g_testBegin;
  59. extern time_t g_testEnd;
  60. // Benchmark command handler
  61. void BenchmarkWithCommand(int argc, const char* const argv[]);
  62. // Top level, prints preamble and postamble
  63. void Benchmark(Test::TestClass suites, double t, double hertz);
  64. // Unkeyed systems
  65. void BenchmarkUnkeyedAlgorithms(double t, double hertz);
  66. // Shared key systems
  67. void BenchmarkSharedKeyedAlgorithms(double t, double hertz);
  68. // Public key systems over integers
  69. void BenchmarkPublicKeyAlgorithms(double t, double hertz);
  70. // Public key systems over elliptic curves
  71. void BenchmarkEllipticCurveAlgorithms(double t, double hertz);
  72. // These are defined in bench1.cpp
  73. extern void OutputResultKeying(double iterations, double timeTaken);
  74. extern void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken);
  75. extern void OutputResultOperations(const char *name, const char *provider, const char *operation, bool pc, unsigned long iterations, double timeTaken);
  76. // These are defined in bench1.cpp
  77. extern void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal);
  78. extern void BenchMark(const char *name, StreamTransformation &cipher, double timeTotal);
  79. extern void BenchMark(const char *name, HashTransformation &ht, double timeTotal);
  80. extern void BenchMark(const char *name, RandomNumberGenerator &rng, double timeTotal);
  81. // These are defined in bench2.cpp
  82. extern void BenchMarkKeying(SimpleKeyingInterface &c, size_t keyLength, const NameValuePairs &params);
  83. extern void BenchMark(const char *name, AuthenticatedSymmetricCipher &cipher, double timeTotal);
  84. NAMESPACE_END // Test
  85. NAMESPACE_END // CryptoPP
  86. #endif