Ninja
canon_perftest.cc
Go to the documentation of this file.
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include "util.h"
19 #include "metrics.h"
20 
21 using namespace std;
22 
23 const char kPath[] =
24  "../../third_party/WebKit/Source/WebCore/"
25  "platform/leveldb/LevelDBWriteBatch.cpp";
26 
27 int main() {
28  vector<int> times;
29  string err;
30 
31  char buf[200];
32  size_t len = strlen(kPath);
33  strcpy(buf, kPath);
34 
35  for (int j = 0; j < 5; ++j) {
36  const int kNumRepetitions = 2000000;
37  int64_t start = GetTimeMillis();
38  uint64_t slash_bits;
39  for (int i = 0; i < kNumRepetitions; ++i) {
40  CanonicalizePath(buf, &len, &slash_bits, &err);
41  }
42  int delta = (int)(GetTimeMillis() - start);
43  times.push_back(delta);
44  }
45 
46  int min = times[0];
47  int max = times[0];
48  float total = 0;
49  for (size_t i = 0; i < times.size(); ++i) {
50  total += times[i];
51  if (times[i] < min)
52  min = times[i];
53  else if (times[i] > max)
54  max = times[i];
55  }
56 
57  printf("min %dms max %dms avg %.1fms\n",
58  min, max, total / times.size());
59 }
bool CanonicalizePath(string *path, uint64_t *slash_bits, string *err)
Definition: util.cc:95
const char kPath[]
int64_t GetTimeMillis()
Get the current time as relative to some epoch.
Definition: metrics.cc:126
signed long long int64_t
A 64-bit integer type.
Definition: win32port.h:28
int main()
unsigned long long uint64_t
Definition: win32port.h:29