Updated the benchmarking code to print the number of flops processed instead of the number of bytes.

This commit is contained in:
Benoit Steiner 2016-01-28 16:51:40 -08:00
parent 8217281ae4
commit a68864b6bc
3 changed files with 9 additions and 10 deletions

View File

@ -41,10 +41,9 @@ class Benchmark {
void RunWithArg(int arg); void RunWithArg(int arg);
}; };
} // namespace testing } // namespace testing
void SetBenchmarkBytesProcessed(int64_t); void SetBenchmarkFlopsProcessed(int64_t);
void StopBenchmarkTiming(); void StopBenchmarkTiming();
void StartBenchmarkTiming(); void StartBenchmarkTiming();
#define BENCHMARK(f) \ #define BENCHMARK(f) \
static ::testing::Benchmark* _benchmark_##f __attribute__((unused)) = \ static ::testing::Benchmark* _benchmark_##f __attribute__((unused)) = \
(new ::testing::Benchmark(#f, f)) (new ::testing::Benchmark(#f, f))

View File

@ -23,7 +23,7 @@
#include <time.h> #include <time.h>
#include <map> #include <map>
static int64_t g_bytes_processed; static int64_t g_flops_processed;
static int64_t g_benchmark_total_time_ns; static int64_t g_benchmark_total_time_ns;
static int64_t g_benchmark_start_time_ns; static int64_t g_benchmark_start_time_ns;
typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap; typedef std::map<std::string, ::testing::Benchmark*> BenchmarkMap;
@ -124,7 +124,7 @@ void Benchmark::Run() {
} }
} }
void Benchmark::RunRepeatedlyWithArg(int iterations, int arg) { void Benchmark::RunRepeatedlyWithArg(int iterations, int arg) {
g_bytes_processed = 0; g_flops_processed = 0;
g_benchmark_total_time_ns = 0; g_benchmark_total_time_ns = 0;
g_benchmark_start_time_ns = NanoTime(); g_benchmark_start_time_ns = NanoTime();
if (fn_ != NULL) { if (fn_ != NULL) {
@ -153,10 +153,10 @@ void Benchmark::RunWithArg(int arg) {
} }
char throughput[100]; char throughput[100];
throughput[0] = '\0'; throughput[0] = '\0';
if (g_benchmark_total_time_ns > 0 && g_bytes_processed > 0) { if (g_benchmark_total_time_ns > 0 && g_flops_processed > 0) {
double mib_processed = static_cast<double>(g_bytes_processed)/1e6; double mflops_processed = static_cast<double>(g_flops_processed)/1e6;
double seconds = static_cast<double>(g_benchmark_total_time_ns)/1e9; double seconds = static_cast<double>(g_benchmark_total_time_ns)/1e9;
snprintf(throughput, sizeof(throughput), " %8.2f MiB/s", mib_processed/seconds); snprintf(throughput, sizeof(throughput), " %8.2f MFlops/s", mflops_processed/seconds);
} }
char full_name[100]; char full_name[100];
if (fn_range_ != NULL) { if (fn_range_ != NULL) {
@ -175,8 +175,8 @@ void Benchmark::RunWithArg(int arg) {
fflush(stdout); fflush(stdout);
} }
} // namespace testing } // namespace testing
void SetBenchmarkBytesProcessed(int64_t x) { void SetBenchmarkFlopsProcessed(int64_t x) {
g_bytes_processed = x; g_flops_processed = x;
} }
void StopBenchmarkTiming() { void StopBenchmarkTiming() {
if (g_benchmark_start_time_ns != 0) { if (g_benchmark_start_time_ns != 0) {

View File

@ -367,7 +367,7 @@ template <typename Device> class BenchmarkSuite {
} }
#endif #endif
StopBenchmarkTiming(); StopBenchmarkTiming();
SetBenchmarkBytesProcessed(num_items); SetBenchmarkFlopsProcessed(num_items);
} }