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 
30  char buf[200];
31  size_t len = strlen(kPath);
32  strcpy(buf, kPath);
33 
34  for (int j = 0; j < 5; ++j) {
35  const int kNumRepetitions = 2000000;
36  int64_t start = GetTimeMillis();
37  uint64_t slash_bits;
38  for (int i = 0; i < kNumRepetitions; ++i) {
39  CanonicalizePath(buf, &len, &slash_bits);
40  }
41  int delta = (int)(GetTimeMillis() - start);
42  times.push_back(delta);
43  }
44 
45  int min = times[0];
46  int max = times[0];
47  float total = 0;
48  for (size_t i = 0; i < times.size(); ++i) {
49  total += times[i];
50  if (times[i] < min)
51  min = times[i];
52  else if (times[i] > max)
53  max = times[i];
54  }
55 
56  printf("min %dms max %dms avg %.1fms\n",
57  min, max, total / times.size());
58 }
const char kPath[]
int main()
int64_t GetTimeMillis()
Get the current time as relative to some epoch.
Definition: metrics.cc:111
Definition: hash_map.h:26
void CanonicalizePath(string *path, uint64_t *slash_bits)
Definition: util.cc:124
unsigned long long uint64_t
Definition: win32port.h:29
signed long long int64_t
A 64-bit integer type.
Definition: win32port.h:28