Chromium Code Reviews

Side by Side 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.
Jump to:
View unified diff |
« no previous file with comments | « third_party/re2/util/atomicops.h ('k') | third_party/re2/util/flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The RE2 Authors. All Rights Reserved. 1 // Copyright 2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 #include "util/util.h" 5 #include "util/util.h"
6 #include "util/flags.h" 6 #include "util/flags.h"
7 #include "util/benchmark.h" 7 #include "util/benchmark.h"
8 #include "re2/re2.h" 8 #include "re2/re2.h"
9 9
10 DEFINE_string(test_tmpdir, "/var/tmp", "temp directory"); 10 DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
11 11
12 using testing::Benchmark; 12 using testing::Benchmark;
13 using namespace re2; 13 using namespace re2;
14 14
15 static Benchmark* benchmarks[10000]; 15 static Benchmark* benchmarks[10000];
16 static int nbenchmarks; 16 static int nbenchmarks;
17 17
18 void Benchmark::Register() { 18 void Benchmark::Register() {
19 benchmarks[nbenchmarks] = this; 19 benchmarks[nbenchmarks] = this;
20 if(lo < 1) 20 if(lo < 1)
21 lo = 1; 21 lo = 1;
22 if(hi < lo) 22 if(hi < lo)
23 hi = lo; 23 hi = lo;
24 nbenchmarks++; 24 nbenchmarks++;
25 } 25 }
26 26
27 static int64 nsec() { 27 static int64 nsec() {
28 #if defined(__APPLE__)
28 struct timeval tv; 29 struct timeval tv;
29 if(gettimeofday(&tv, 0) < 0) 30 if(gettimeofday(&tv, 0) < 0)
30 return -1; 31 return -1;
31 return (int64)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000; 32 return (int64)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000;
33 #elif defined(_WIN32)
34 // https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408.asp x
35 // describes how to query ticks and convert to microseconds. Of course,
36 // what we want in this case are nanoseconds. Also, note that .QuadPart
37 // is a signed 64-bit integer, so casting to int64 shouldn't be needed.
38 LARGE_INTEGER freq;
39 QueryPerformanceFrequency(&freq);
40 LARGE_INTEGER ticks;
41 QueryPerformanceCounter(&ticks);
42 ticks.QuadPart *= 1000*1000*1000;
43 ticks.QuadPart /= freq.QuadPart;
44 return ticks.QuadPart;
45 #else
46 struct timespec tp;
47 if(clock_gettime(CLOCK_REALTIME, &tp) < 0)
48 return -1;
49 return (int64)tp.tv_sec*1000*1000*1000 + tp.tv_nsec;
50 #endif
32 } 51 }
33 52
34 static int64 bytes; 53 static int64 bytes;
35 static int64 ns; 54 static int64 ns;
36 static int64 t0; 55 static int64 t0;
37 static int64 items; 56 static int64 items;
38 57
39 void SetBenchmarkBytesProcessed(long long x) { 58 void SetBenchmarkBytesProcessed(long long x) {
40 bytes = x; 59 bytes = x;
41 } 60 }
(...skipping 56 matching lines...)
98 // TODO(rsc): Threaded benchmarks. 117 // TODO(rsc): Threaded benchmarks.
99 if(nthread != 1) 118 if(nthread != 1)
100 return; 119 return;
101 120
102 // run once in case it's expensive 121 // run once in case it's expensive
103 n = 1; 122 n = 1;
104 runN(b, n, siz); 123 runN(b, n, siz);
105 while(ns < (int)1e9 && n < (int)1e9) { 124 while(ns < (int)1e9 && n < (int)1e9) {
106 last = n; 125 last = n;
107 if(ns/n == 0) 126 if(ns/n == 0)
108 » » » n = 1e9; 127 » » » n = (int)1e9;
109 else 128 else
110 » » » n = 1e9 / (ns/n); 129 » » » n = (int)1e9 / static_cast<int>(ns/n);
111 130
112 n = max(last+1, min(n+n/2, 100*last)); 131 n = max(last+1, min(n+n/2, 100*last));
113 n = round(n); 132 n = round(n);
114 runN(b, n, siz); 133 runN(b, n, siz);
115 } 134 }
116 135
117 char mb[100]; 136 char mb[100];
118 char suf[100]; 137 char suf[100];
119 mb[0] = '\0'; 138 mb[0] = '\0';
120 suf[0] = '\0'; 139 suf[0] = '\0';
(...skipping 23 matching lines...)
144 int main(int argc, const char** argv) { 163 int main(int argc, const char** argv) {
145 for(int i = 0; i < nbenchmarks; i++) { 164 for(int i = 0; i < nbenchmarks; i++) {
146 Benchmark* b = benchmarks[i]; 165 Benchmark* b = benchmarks[i];
147 if(match(b->name, argc, argv)) 166 if(match(b->name, argc, argv))
148 for(int j = b->threadlo; j <= b->threadhi; j++) 167 for(int j = b->threadlo; j <= b->threadhi; j++)
149 for(int k = max(b->lo, 1); k <= max(b->hi, 1); k <<=1) 168 for(int k = max(b->lo, 1); k <= max(b->hi, 1); k <<=1)
150 RunBench(b, j, k); 169 RunBench(b, j, k);
151 } 170 }
152 } 171 }
153 172
OLDNEW
« 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