summaryrefslogtreecommitdiff
path: root/bench1.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2018-10-14 03:50:13 -0400
committerJeffrey Walton <noloader@gmail.com>2018-10-14 03:50:13 -0400
commit4e78abe58409332ce1b3d2fdb737b20dcfcadc7d (patch)
tree80b81a1d577583fc454ac7e0e01d644207f5662a /bench1.cpp
parentc65cd7c365e3b9398bb5bef09e6f1a5acf6eeb08 (diff)
downloadcryptopp-git-4e78abe58409332ce1b3d2fdb737b20dcfcadc7d.tar.gz
Use HertzToString for friendly CPU speed
Diffstat (limited to 'bench1.cpp')
-rw-r--r--bench1.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/bench1.cpp b/bench1.cpp
index c0c08c0f..2fe6fd7d 100644
--- a/bench1.cpp
+++ b/bench1.cpp
@@ -45,6 +45,23 @@ double g_allocatedTime = 0.0, g_hertz = 0.0, g_logTotal = 0.0;
unsigned int g_logCount = 0;
time_t g_testBegin, g_testEnd;
+inline std::string HertzToString(double hz)
+{
+ std::ostringstream oss;
+ oss.precision(3);
+
+ if (hz >= 0.999e+9)
+ oss << hz / 1e+9 << " GHz";
+ else if (hz >= 0.999e+6)
+ oss << hz / 1e+6 << " MHz";
+ else if (hz >= 0.999e+3)
+ oss << hz / 1e+3 << " KHz";
+ else
+ oss << hz << " Hz";
+
+ return oss.str();
+}
+
void OutputResultBytes(const char *name, const char *provider, double length, double timeTaken)
{
std::ostringstream oss;
@@ -305,7 +322,7 @@ void AddHtmlHeader()
oss << "\n<P>Here are speed benchmarks for some commonly used cryptographic algorithms.</P>";
if (g_hertz > 1.0f)
- oss << "\n<P>CPU frequency of the test platform is " << g_hertz << " Hz.</P>";
+ oss << "\n<P>CPU frequency of the test platform is " << HertzToString(g_hertz) << ".</P>";
else
oss << "\n<P>CPU frequency of the test platform was not provided.</P>" << std::endl;