diff --git a/src/console_reporter.cc b/src/console_reporter.cc index 2cdd995dd8..044d9f350c 100644 --- a/src/console_reporter.cc +++ b/src/console_reporter.cc @@ -180,7 +180,7 @@ void ConsoleReporter::PrintRunData(const Run& result) { for (auto& c : result.counters) { const std::size_t cNameLen = - std::max(std::string::size_type(10), c.first.length()); + std::max(static_cast(10), c.first.length()); std::string s; const char* unit = ""; if (result.run_type == Run::RT_Aggregate && diff --git a/src/json_reporter.cc b/src/json_reporter.cc index 2ab51d287d..1348237dc7 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -85,6 +85,12 @@ std::string FormatKV(std::string const& key, int64_t value) { return ss.str(); } +std::string FormatKV(std::string const& key, int value) { + std::stringstream ss; + ss << '"' << StrEscape(key) << "\": " << value; + return ss.str(); +} + std::string FormatKV(std::string const& key, double value) { std::stringstream ss; ss << '"' << StrEscape(key) << "\": "; @@ -183,7 +189,7 @@ bool JSONReporter::ReportContext(const Context& context) { out << ",\n"; // NOTE: our json schema is not strictly tied to the library version! - out << indent << FormatKV("json_schema_version", int64_t(1)); + out << indent << FormatKV("json_schema_version", 1); std::map* global_context = internal::GetGlobalContext(); diff --git a/src/statistics.cc b/src/statistics.cc index 12eb5602d9..3bcc1e46fd 100644 --- a/src/statistics.cc +++ b/src/statistics.cc @@ -176,7 +176,7 @@ std::vector ComputeStats( } const double iteration_rescale_factor = - double(reports.size()) / double(run_iterations); + static_cast(reports.size()) / static_cast(run_iterations); for (const auto& Stat : *reports[0].statistics) { // Get the data from the accumulator to BenchmarkReporter::Run's. diff --git a/test/basic_test.cc b/test/basic_test.cc index c25bec7ddd..c3ac4946d8 100644 --- a/test/basic_test.cc +++ b/test/basic_test.cc @@ -5,7 +5,8 @@ void BM_empty(benchmark::State& state) { for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } } diff --git a/test/diagnostics_test.cc b/test/diagnostics_test.cc index 69b21221c6..caa2771b00 100644 --- a/test/diagnostics_test.cc +++ b/test/diagnostics_test.cc @@ -51,7 +51,8 @@ void BM_diagnostic_test(benchmark::State& state) { } for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } @@ -71,7 +72,8 @@ void BM_diagnostic_test_keep_running(benchmark::State& state) { } while (state.KeepRunning()) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } diff --git a/test/link_main_test.cc b/test/link_main_test.cc index 131937eebc..b0a37c06e1 100644 --- a/test/link_main_test.cc +++ b/test/link_main_test.cc @@ -2,7 +2,8 @@ void BM_empty(benchmark::State& state) { for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } } diff --git a/test/memory_manager_test.cc b/test/memory_manager_test.cc index 4df674d586..ebb72b0341 100644 --- a/test/memory_manager_test.cc +++ b/test/memory_manager_test.cc @@ -14,7 +14,8 @@ class TestMemoryManager : public benchmark::MemoryManager { void BM_empty(benchmark::State& state) { for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } } diff --git a/test/output_test_helper.cc b/test/output_test_helper.cc index e48b465483..e85e3d3108 100644 --- a/test/output_test_helper.cc +++ b/test/output_test_helper.cc @@ -539,7 +539,7 @@ std::string GetFileReporterOutput(int argc, char* argv[]) { tmp += tmp_file_name; new_argv.emplace_back(const_cast(tmp.c_str())); - argc = int(new_argv.size()); + argc = static_cast(new_argv.size()); benchmark::Initialize(&argc, new_argv.data()); benchmark::RunSpecifiedBenchmarks(); diff --git a/test/perf_counters_test.cc b/test/perf_counters_test.cc index 3cc593e629..bf15465570 100644 --- a/test/perf_counters_test.cc +++ b/test/perf_counters_test.cc @@ -14,7 +14,8 @@ BM_DECLARE_string(benchmark_perf_counters); static void BM_Simple(benchmark::State& state) { for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } } diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc index 7867165d1f..ce6ddf2998 100644 --- a/test/reporter_output_test.cc +++ b/test/reporter_output_test.cc @@ -96,7 +96,8 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_basic\",%csv_report$"}}); void BM_bytes_per_second(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } state.SetBytesProcessed(1); @@ -128,7 +129,8 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_bytes_per_second\",%csv_bytes_report$"}}); void BM_items_per_second(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } state.SetItemsProcessed(1); @@ -409,7 +411,8 @@ ADD_CASES(TC_ConsoleOut, {{"^BM_BigArgs/1073741824 %console_report$"}, void BM_Complexity_O1(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } state.SetComplexityN(state.range(0)); diff --git a/test/skip_with_error_test.cc b/test/skip_with_error_test.cc index 040bd4219c..bec5437326 100644 --- a/test/skip_with_error_test.cc +++ b/test/skip_with_error_test.cc @@ -143,7 +143,8 @@ ADD_CASES("BM_error_during_running_ranged_for", void BM_error_after_running(benchmark::State& state) { for (auto _ : state) { - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } if (state.thread_index() <= (state.threads() / 2)) { diff --git a/test/user_counters_tabular_test.cc b/test/user_counters_tabular_test.cc index cfc1ab069c..d26120e082 100644 --- a/test/user_counters_tabular_test.cc +++ b/test/user_counters_tabular_test.cc @@ -64,7 +64,8 @@ ADD_CASES(TC_CSVOut, {{"%csv_header," void BM_Counters_Tabular(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -375,7 +376,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_Tabular/repeats:2/threads:2$", void BM_CounterRates_Tabular(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; diff --git a/test/user_counters_test.cc b/test/user_counters_test.cc index 22252acbf6..d3fd4a6eab 100644 --- a/test/user_counters_test.cc +++ b/test/user_counters_test.cc @@ -67,7 +67,8 @@ int num_calls1 = 0; void BM_Counters_WithBytesAndItemsPSec(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } state.counters["foo"] = 1; @@ -119,7 +120,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_WithBytesAndItemsPSec", void BM_Counters_Rate(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -163,7 +165,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_Rate", &CheckRate); void BM_Invert(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -204,7 +207,8 @@ CHECK_BENCHMARK_RESULTS("BM_Invert", &CheckInvert); void BM_Counters_InvertedRate(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -333,7 +337,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_AvgThreads/threads:%int", void BM_Counters_AvgThreadsRate(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -421,7 +426,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_IterationInvariant", void BM_Counters_kIsIterationInvariantRate(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark; @@ -513,7 +519,8 @@ CHECK_BENCHMARK_RESULTS("BM_Counters_AvgIterations", &CheckAvgIterations); void BM_Counters_kAvgIterationsRate(benchmark::State& state) { for (auto _ : state) { // This test requires a non-zero CPU time to avoid divide-by-zero - auto iterations = double(state.iterations()) * double(state.iterations()); + auto iterations = static_cast(state.iterations()) * + static_cast(state.iterations()); benchmark::DoNotOptimize(iterations); } namespace bm = benchmark;