From 4e78abe58409332ce1b3d2fdb737b20dcfcadc7d Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 14 Oct 2018 03:50:13 -0400 Subject: [PATCH] Use HertzToString for friendly CPU speed --- bench1.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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

Here are speed benchmarks for some commonly used cryptographic algorithms.

"; if (g_hertz > 1.0f) - oss << "\n

CPU frequency of the test platform is " << g_hertz << " Hz.

"; + oss << "\n

CPU frequency of the test platform is " << HertzToString(g_hertz) << ".

"; else oss << "\n

CPU frequency of the test platform was not provided.

" << std::endl;