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

Side by Side Diff: third_party/re2/util/benchmark.cc

Issue 1530113002: Revert of Update re2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | 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 »
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__)
29 struct timeval tv; 28 struct timeval tv;
30 if(gettimeofday(&tv, 0) < 0) 29 if(gettimeofday(&tv, 0) < 0)
31 return -1; 30 return -1;
32 return (int64)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000; 31 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
51 } 32 }
52 33
53 static int64 bytes; 34 static int64 bytes;
54 static int64 ns; 35 static int64 ns;
55 static int64 t0; 36 static int64 t0;
56 static int64 items; 37 static int64 items;
57 38
58 void SetBenchmarkBytesProcessed(long long x) { 39 void SetBenchmarkBytesProcessed(long long x) {
59 bytes = x; 40 bytes = x;
60 } 41 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // TODO(rsc): Threaded benchmarks. 98 // TODO(rsc): Threaded benchmarks.
118 if(nthread != 1) 99 if(nthread != 1)
119 return; 100 return;
120 101
121 // run once in case it's expensive 102 // run once in case it's expensive
122 n = 1; 103 n = 1;
123 runN(b, n, siz); 104 runN(b, n, siz);
124 while(ns < (int)1e9 && n < (int)1e9) { 105 while(ns < (int)1e9 && n < (int)1e9) {
125 last = n; 106 last = n;
126 if(ns/n == 0) 107 if(ns/n == 0)
127 » » » n = (int)1e9; 108 » » » n = 1e9;
128 else 109 else
129 » » » n = (int)1e9 / static_cast<int>(ns/n); 110 » » » n = 1e9 / (ns/n);
130 111
131 n = max(last+1, min(n+n/2, 100*last)); 112 n = max(last+1, min(n+n/2, 100*last));
132 n = round(n); 113 n = round(n);
133 runN(b, n, siz); 114 runN(b, n, siz);
134 } 115 }
135 116
136 char mb[100]; 117 char mb[100];
137 char suf[100]; 118 char suf[100];
138 mb[0] = '\0'; 119 mb[0] = '\0';
139 suf[0] = '\0'; 120 suf[0] = '\0';
(...skipping 23 matching lines...) Expand all
163 int main(int argc, const char** argv) { 144 int main(int argc, const char** argv) {
164 for(int i = 0; i < nbenchmarks; i++) { 145 for(int i = 0; i < nbenchmarks; i++) {
165 Benchmark* b = benchmarks[i]; 146 Benchmark* b = benchmarks[i];
166 if(match(b->name, argc, argv)) 147 if(match(b->name, argc, argv))
167 for(int j = b->threadlo; j <= b->threadhi; j++) 148 for(int j = b->threadlo; j <= b->threadhi; j++)
168 for(int k = max(b->lo, 1); k <= max(b->hi, 1); k <<=1) 149 for(int k = max(b->lo, 1); k <= max(b->hi, 1); k <<=1)
169 RunBench(b, j, k); 150 RunBench(b, j, k);
170 } 151 }
171 } 152 }
172 153
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
This is Rietveld 408576698