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
21using namespace std;
22
23const char kPath[] =
24 "../../third_party/WebKit/Source/WebCore/"
25 "platform/leveldb/LevelDBWriteBatch.cpp";
26
27int 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}
59