Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: third_party/re2/util/benchmark.cc

Issue 1516543002: Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated update instructions Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/re2/util/atomicops.h ('k') | third_party/re2/util/flags.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/util/benchmark.cc
diff --git a/third_party/re2/util/benchmark.cc b/third_party/re2/util/benchmark.cc
index c3aad7ed89ad48654c8d00ffa9ecfbfcf6fafc7a..b77e22d781ae02ccf9a9d0bd832df87e2b780d8c 100644
--- a/third_party/re2/util/benchmark.cc
+++ b/third_party/re2/util/benchmark.cc
@@ -25,10 +25,29 @@ void Benchmark::Register() {
}
static int64 nsec() {
+#if defined(__APPLE__)
struct timeval tv;
if(gettimeofday(&tv, 0) < 0)
return -1;
return (int64)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000;
+#elif defined(_WIN32)
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408.aspx
+ // describes how to query ticks and convert to microseconds. Of course,
+ // what we want in this case are nanoseconds. Also, note that .QuadPart
+ // is a signed 64-bit integer, so casting to int64 shouldn't be needed.
+ LARGE_INTEGER freq;
+ QueryPerformanceFrequency(&freq);
+ LARGE_INTEGER ticks;
+ QueryPerformanceCounter(&ticks);
+ ticks.QuadPart *= 1000*1000*1000;
+ ticks.QuadPart /= freq.QuadPart;
+ return ticks.QuadPart;
+#else
+ struct timespec tp;
+ if(clock_gettime(CLOCK_REALTIME, &tp) < 0)
+ return -1;
+ return (int64)tp.tv_sec*1000*1000*1000 + tp.tv_nsec;
+#endif
}
static int64 bytes;
@@ -105,9 +124,9 @@ void RunBench(Benchmark* b, int nthread, int siz) {
while(ns < (int)1e9 && n < (int)1e9) {
last = n;
if(ns/n == 0)
- n = 1e9;
+ n = (int)1e9;
else
- n = 1e9 / (ns/n);
+ n = (int)1e9 / static_cast<int>(ns/n);
n = max(last+1, min(n+n/2, 100*last));
n = round(n);
« no previous file with comments | « third_party/re2/util/atomicops.h ('k') | third_party/re2/util/flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698