{"action":"created","comment":{"url":"https://api.github.com/repos/google/benchmark/pulls/comments/26346863","id":26346863,"diff_hunk":"@@ -57,124 +57,121 @@ DEFINE_double(benchmark_min_time, 0.5,\n               \"of the benchmark execution, regardless of number of \"\n               \"threads.\");\n \n-DEFINE_bool(benchmark_memory_usage, false,\n-            \"Report memory usage for all benchmarks\");\n-\n DEFINE_int32(benchmark_repetitions, 1,\n              \"The number of runs of each benchmark. If greater than 1, the \"\n              \"mean and standard deviation of the runs will be reported.\");\n \n-DEFINE_int32(v, 0, \"The level of verbose logging to output\");\n DEFINE_bool(color_print, true, \"Enables colorized logging.\");\n \n-// Will be non-empty if heap checking is turned on, which would\n-// invalidate any benchmarks.\n-DECLARE_string(heap_check);\n+DEFINE_int32(v, 0, \"The level of verbose logging to output\");\n+\n \n // The \"\"'s catch people who don't pass in a literal for \"str\"\n #define strliterallen(str) (sizeof(\"\" str \"\") - 1)\n \n // Must use a string literal for prefix.\n-#define memprefix(str, len, prefix)                  \\\n-  ((((len) >= strliterallen(prefix)) &&              \\\n-    memcmp(str, prefix, strliterallen(prefix)) == 0) \\\n-       ? str + strliterallen(prefix)                 \\\n-       : NULL)\n+#define memprefix(str, len, prefix)                       \\\n+  ((((len) >= strliterallen(prefix)) &&                   \\\n+    std::memcmp(str, prefix, strliterallen(prefix)) == 0) \\\n+       ? str + strliterallen(prefix)                      \\\n+       : nullptr)\n+\n \n namespace benchmark {\n+\n+namespace internal {\n+\n+// NOTE: This is a dummy \"mutex\" type used to denote the actual mutex\n+// returned by GetBenchmarkLock(). This is only used to placate the thread\n+// safety warnings by giving the return of GetBenchmarkLock() a name.\n+struct CAPABILITY(\"mutex\") BenchmarkLockType {};\n+BenchmarkLockType BenchmarkLockVar;\n+\n+} // end namespace internal\n+\n+inline Mutex& RETURN_CAPABILITY(::benchmark::internal::BenchmarkLockVar)\n+GetBenchmarkLock()\n+{\n+  static Mutex lock;\n+  return lock;\n+}\n+\n namespace {\n+\n // For non-dense Range, intermediate values are powers of kRangeMultiplier.\n static const int kRangeMultiplier = 8;\n-\n-std::mutex starting_mutex;\n-std::condition_variable starting_cv;\n+static const int kMaxIterations = 1000000000;\n \n bool running_benchmark = false;\n \n-// Should this benchmark report memory usage?\n-bool get_memory_usage;\n+// Global variable so that a benchmark can cause a little extra printing\n+std::string* GetReportLabel() {\n+    static std::string label GUARDED_BY(GetBenchmarkLock());\n+    return &label;\n+}\n \n // Should this benchmark base decisions off of real time rather than\n // cpu time?\n-bool use_real_time;\n-\n-// Overhead of an empty benchmark.\n-double overhead = 0.0;\n-\n-// Return prefix to print in front of each reported line\n-const char* Prefix() {\n-#ifdef NDEBUG\n-  return \"\";\n-#else\n-  return \"DEBUG: \";\n-#endif\n-}\n+bool use_real_time GUARDED_BY(GetBenchmarkLock());\n \n-// TODO\n-// static internal::MallocCounter *benchmark_mc;\n+// TODO(ericwf): support MallocCounter.\n+//static benchmark::MallocCounter *benchmark_mc;\n \n-bool CpuScalingEnabled() {\n+static bool CpuScalingEnabled() {\n   // On Linux, the CPUfreq subsystem exposes CPU information as files on the\n   // local file system. If reading the exported files fails, then we may not be\n   // running on Linux, so we silently ignore all the read errors.\n   for (int cpu = 0, num_cpus = NumCPUs(); cpu < num_cpus; ++cpu) {\n-    std::stringstream ss;\n-    ss << \"/sys/devices/system/cpu/cpu\" << cpu << \"/cpufreq/scaling_governor\";\n-    std::string governor_file = ss.str();\n+    std::string governor_file = StrCat(\"/sys/devices/system/cpu/cpu\", cpu,\n+                                       \"/cpufreq/scaling_governor\");\n     FILE* file = fopen(governor_file.c_str(), \"r\");\n     if (!file) break;\n     char buff[16];\n     size_t bytes_read = fread(buff, 1, sizeof(buff), file);\n     fclose(file);\n-    if (memprefix(buff, bytes_read, \"performance\") == NULL) return true;\n+    if (memprefix(buff, bytes_read, \"performance\") == nullptr) return true;\n   }\n   return false;\n }\n \n-// Given a collection of reports, computes their mean and stddev.\n-// REQUIRES: all runs in \"reports\" must be from the same benchmark.\n void ComputeStats(const std::vector<BenchmarkReporter::Run>& reports,\n                   BenchmarkReporter::Run* mean_data,\n                   BenchmarkReporter::Run* stddev_data) {\n+  CHECK(reports.size() >= 2) << \"Cannot compute stats for less than 2 reports\";\n   // Accumulators.\n   Stat1_d real_accumulated_time_stat;\n   Stat1_d cpu_accumulated_time_stat;\n-  Stat1_d items_per_second_stat;\n   Stat1_d bytes_per_second_stat;\n-  Stat1_d iterations_stat;\n-  Stat1MinMax_d max_heapbytes_used_stat;\n+  Stat1_d items_per_second_stat;\n+  // All repetitions should be run with the same number of iterations so we\n+  // can take this information from the first benchmark.\n+  std::size_t const run_iterations = reports.front().iterations;\n \n   // Populate the accumulators.\n-  for (std::vector<BenchmarkReporter::Run>::const_iterator it = reports.begin();\n-       it != reports.end(); ++it) {\n-    CHECK_EQ(reports[0].benchmark_name, it->benchmark_name);\n+  for (BenchmarkReporter::Run const& run : reports) {\n+    CHECK_EQ(reports[0].benchmark_name, run.benchmark_name);\n+    CHECK_EQ(run_iterations, run.iterations);\n     real_accumulated_time_stat +=\n-        Stat1_d(it->real_accumulated_time / it->iterations, it->iterations);\n+        Stat1_d(run.real_accumulated_time/run.iterations, run.iterations);\n     cpu_accumulated_time_stat +=\n-        Stat1_d(it->cpu_accumulated_time / it->iterations, it->iterations);\n-    items_per_second_stat += Stat1_d(it->items_per_second, it->iterations);\n-    bytes_per_second_stat += Stat1_d(it->bytes_per_second, it->iterations);\n-    iterations_stat += Stat1_d(it->iterations, it->iterations);\n-    max_heapbytes_used_stat +=\n-        Stat1MinMax_d(it->max_heapbytes_used, it->iterations);\n+        Stat1_d(run.cpu_accumulated_time/run.iterations, run.iterations);\n+    items_per_second_stat += Stat1_d(run.items_per_second, run.iterations);\n+    bytes_per_second_stat += Stat1_d(run.bytes_per_second, run.iterations);\n   }\n \n-  // Get the data from the accumulator to BenchmarkRunData's.  In the\n-  // computations below we must multiply by the number of iterations since\n-  // PrintRunData will divide by it.\n+  // Get the data from the accumulator to BenchmarkReporter::Run's.\n   mean_data->benchmark_name = reports[0].benchmark_name + \"_mean\";\n-  mean_data->iterations = iterations_stat.Mean();\n+  mean_data->iterations = run_iterations;","path":"src/benchmark.cc","position":210,"original_position":210,"commit_id":"ca7373796827ef7c5f23765f11db70c40e3a5ec4","original_commit_id":"ca7373796827ef7c5f23765f11db70c40e3a5ec4","user":{"login":"dominichamon","id":510002,"avatar_url":"https://avatars.githubusercontent.com/u/510002?v=3","gravatar_id":"","url":"https://api.github.com/users/dominichamon","html_url":"https://github.com/dominichamon","followers_url":"https://api.github.com/users/dominichamon/followers","following_url":"https://api.github.com/users/dominichamon/following{/other_user}","gists_url":"https://api.github.com/users/dominichamon/gists{/gist_id}","starred_url":"https://api.github.com/users/dominichamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominichamon/subscriptions","organizations_url":"https://api.github.com/users/dominichamon/orgs","repos_url":"https://api.github.com/users/dominichamon/repos","events_url":"https://api.github.com/users/dominichamon/events{/privacy}","received_events_url":"https://api.github.com/users/dominichamon/received_events","type":"User","site_admin":false},"body":"this is still a regression over the current version. if there are multiple runs (when repetitions is set?) this will not reflect the mean as expected by the row label.","created_at":"2015-03-12T21:36:26Z","updated_at":"2015-03-12T21:36:26Z","html_url":"https://github.com/google/benchmark/pull/86#discussion_r26346863","pull_request_url":"https://api.github.com/repos/google/benchmark/pulls/86","_links":{"self":{"href":"https://api.github.com/repos/google/benchmark/pulls/comments/26346863"},"html":{"href":"https://github.com/google/benchmark/pull/86#discussion_r26346863"},"pull_request":{"href":"https://api.github.com/repos/google/benchmark/pulls/86"}}},"pull_request":{"url":"https://api.github.com/repos/google/benchmark/pulls/86","id":30808044,"html_url":"https://github.com/google/benchmark/pull/86","diff_url":"https://github.com/google/benchmark/pull/86.diff","patch_url":"https://github.com/google/benchmark/pull/86.patch","issue_url":"https://api.github.com/repos/google/benchmark/issues/86","number":86,"state":"open","locked":false,"title":"Change timing internals","user":{"login":"EricWF","id":1176427,"avatar_url":"https://avatars.githubusercontent.com/u/1176427?v=3","gravatar_id":"","url":"https://api.github.com/users/EricWF","html_url":"https://github.com/EricWF","followers_url":"https://api.github.com/users/EricWF/followers","following_url":"https://api.github.com/users/EricWF/following{/other_user}","gists_url":"https://api.github.com/users/EricWF/gists{/gist_id}","starred_url":"https://api.github.com/users/EricWF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EricWF/subscriptions","organizations_url":"https://api.github.com/users/EricWF/orgs","repos_url":"https://api.github.com/users/EricWF/repos","events_url":"https://api.github.com/users/EricWF/events{/privacy}","received_events_url":"https://api.github.com/users/EricWF/received_events","type":"User","site_admin":false},"body":"Finally upgrade the timing internals!\r\n\r\nThe problem is the current version is that checking the time every iteration of the benchmark introduces a large amount of jitter and overhead into the timings.\r\n\r\nThis version fixes that problem by only checking the time at the beginning and end of every benchmark run.\r\nIt uses an iteration counter in state.KeepRunning() to track the number of times to run the benchmarks.","created_at":"2015-03-09T22:52:56Z","updated_at":"2015-03-12T21:36:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"51d263a3d2ebce72c0c46bf43659bae8a89fee64","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/benchmark/pulls/86/commits","review_comments_url":"https://api.github.com/repos/google/benchmark/pulls/86/comments","review_comment_url":"https://api.github.com/repos/google/benchmark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/benchmark/issues/86/comments","statuses_url":"https://api.github.com/repos/google/benchmark/statuses/ca7373796827ef7c5f23765f11db70c40e3a5ec4","head":{"label":"google:final-step","ref":"final-step","sha":"ca7373796827ef7c5f23765f11db70c40e3a5ec4","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":15122806,"name":"benchmark","full_name":"google/benchmark","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/benchmark","description":"A microbenchmark support library","fork":false,"url":"https://api.github.com/repos/google/benchmark","forks_url":"https://api.github.com/repos/google/benchmark/forks","keys_url":"https://api.github.com/repos/google/benchmark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/benchmark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/benchmark/teams","hooks_url":"https://api.github.com/repos/google/benchmark/hooks","issue_events_url":"https://api.github.com/repos/google/benchmark/issues/events{/number}","events_url":"https://api.github.com/repos/google/benchmark/events","assignees_url":"https://api.github.com/repos/google/benchmark/assignees{/user}","branches_url":"https://api.github.com/repos/google/benchmark/branches{/branch}","tags_url":"https://api.github.com/repos/google/benchmark/tags","blobs_url":"https://api.github.com/repos/google/benchmark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/benchmark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/benchmark/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/benchmark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/benchmark/statuses/{sha}","languages_url":"https://api.github.com/repos/google/benchmark/languages","stargazers_url":"https://api.github.com/repos/google/benchmark/stargazers","contributors_url":"https://api.github.com/repos/google/benchmark/contributors","subscribers_url":"https://api.github.com/repos/google/benchmark/subscribers","subscription_url":"https://api.github.com/repos/google/benchmark/subscription","commits_url":"https://api.github.com/repos/google/benchmark/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/benchmark/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/benchmark/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/benchmark/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/benchmark/contents/{+path}","compare_url":"https://api.github.com/repos/google/benchmark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/benchmark/merges","archive_url":"https://api.github.com/repos/google/benchmark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/benchmark/downloads","issues_url":"https://api.github.com/repos/google/benchmark/issues{/number}","pulls_url":"https://api.github.com/repos/google/benchmark/pulls{/number}","milestones_url":"https://api.github.com/repos/google/benchmark/milestones{/number}","notifications_url":"https://api.github.com/repos/google/benchmark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/benchmark/labels{/name}","releases_url":"https://api.github.com/repos/google/benchmark/releases{/id}","created_at":"2013-12-12T00:10:48Z","updated_at":"2015-03-12T21:16:41Z","pushed_at":"2015-03-12T20:54:19Z","git_url":"git://github.com/google/benchmark.git","ssh_url":"git@github.com:google/benchmark.git","clone_url":"https://github.com/google/benchmark.git","svn_url":"https://github.com/google/benchmark","homepage":"","size":1523,"stargazers_count":291,"watchers_count":291,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":12,"forks":50,"open_issues":12,"watchers":291,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"522a58916ae6b96a51f10c15b59452a6eb5e1254","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":15122806,"name":"benchmark","full_name":"google/benchmark","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/benchmark","description":"A microbenchmark support library","fork":false,"url":"https://api.github.com/repos/google/benchmark","forks_url":"https://api.github.com/repos/google/benchmark/forks","keys_url":"https://api.github.com/repos/google/benchmark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/benchmark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/benchmark/teams","hooks_url":"https://api.github.com/repos/google/benchmark/hooks","issue_events_url":"https://api.github.com/repos/google/benchmark/issues/events{/number}","events_url":"https://api.github.com/repos/google/benchmark/events","assignees_url":"https://api.github.com/repos/google/benchmark/assignees{/user}","branches_url":"https://api.github.com/repos/google/benchmark/branches{/branch}","tags_url":"https://api.github.com/repos/google/benchmark/tags","blobs_url":"https://api.github.com/repos/google/benchmark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/benchmark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/benchmark/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/benchmark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/benchmark/statuses/{sha}","languages_url":"https://api.github.com/repos/google/benchmark/languages","stargazers_url":"https://api.github.com/repos/google/benchmark/stargazers","contributors_url":"https://api.github.com/repos/google/benchmark/contributors","subscribers_url":"https://api.github.com/repos/google/benchmark/subscribers","subscription_url":"https://api.github.com/repos/google/benchmark/subscription","commits_url":"https://api.github.com/repos/google/benchmark/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/benchmark/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/benchmark/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/benchmark/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/benchmark/contents/{+path}","compare_url":"https://api.github.com/repos/google/benchmark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/benchmark/merges","archive_url":"https://api.github.com/repos/google/benchmark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/benchmark/downloads","issues_url":"https://api.github.com/repos/google/benchmark/issues{/number}","pulls_url":"https://api.github.com/repos/google/benchmark/pulls{/number}","milestones_url":"https://api.github.com/repos/google/benchmark/milestones{/number}","notifications_url":"https://api.github.com/repos/google/benchmark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/benchmark/labels{/name}","releases_url":"https://api.github.com/repos/google/benchmark/releases{/id}","created_at":"2013-12-12T00:10:48Z","updated_at":"2015-03-12T21:16:41Z","pushed_at":"2015-03-12T20:54:19Z","git_url":"git://github.com/google/benchmark.git","ssh_url":"git@github.com:google/benchmark.git","clone_url":"https://github.com/google/benchmark.git","svn_url":"https://github.com/google/benchmark","homepage":"","size":1523,"stargazers_count":291,"watchers_count":291,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":12,"forks":50,"open_issues":12,"watchers":291,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/benchmark/pulls/86"},"html":{"href":"https://github.com/google/benchmark/pull/86"},"issue":{"href":"https://api.github.com/repos/google/benchmark/issues/86"},"comments":{"href":"https://api.github.com/repos/google/benchmark/issues/86/comments"},"review_comments":{"href":"https://api.github.com/repos/google/benchmark/pulls/86/comments"},"review_comment":{"href":"https://api.github.com/repos/google/benchmark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/benchmark/pulls/86/commits"},"statuses":{"href":"https://api.github.com/repos/google/benchmark/statuses/ca7373796827ef7c5f23765f11db70c40e3a5ec4"}}}}