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 const char kPath[] =
22  "../../third_party/WebKit/Source/WebCore/"
23  "platform/leveldb/LevelDBWriteBatch.cpp";
24 
25 int main() {
26  vector<int> times;
27  string err;
28 
29  char buf[200];
30  size_t len = strlen(kPath);
31  strcpy(buf, kPath);
32 
33  for (int j = 0; j < 5; ++j) {
34  const int kNumRepetitions = 2000000;
35  int64_t start = GetTimeMillis();
36  for (int i = 0; i < kNumRepetitions; ++i) {
37  CanonicalizePath(buf, &len, &err);
38  }
39  int delta = (int)(GetTimeMillis() - start);
40  times.push_back(delta);
41  }
42 
43  int min = times[0];
44  int max = times[0];
45  float total = 0;
46  for (size_t i = 0; i < times.size(); ++i) {
47  total += times[i];
48  if (times[i] < min)
49  min = times[i];
50  else if (times[i] > max)
51  max = times[i];
52  }
53 
54  printf("min %dms max %dms avg %.1fms\n",
55  min, max, total / times.size());
56 }
const char kPath[]
int64_t GetTimeMillis()
Get the current time as relative to some epoch.
Definition: metrics.cc:122
bool CanonicalizePath(string *path, string *err)
Canonicalize a path like "foo/../bar.h" into just "bar.h".
Definition: util.cc:87
signed long long int64_t
A 64-bit integer type.
Definition: win32port.h:21
int main()