• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main()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     uint64_t slash_bits;
37     for (int i = 0; i < kNumRepetitions; ++i) {
38       CanonicalizePath(buf, &len, &slash_bits, &err);
39     }
40     int delta = (int)(GetTimeMillis() - start);
41     times.push_back(delta);
42   }
43 
44   int min = times[0];
45   int max = times[0];
46   float total = 0;
47   for (size_t i = 0; i < times.size(); ++i) {
48     total += times[i];
49     if (times[i] < min)
50       min = times[i];
51     else if (times[i] > max)
52       max = times[i];
53   }
54 
55   printf("min %dms  max %dms  avg %.1fms\n",
56          min, max, total / times.size());
57 }
58