Ninja
canon_perftest.cc
Go to the documentation of this file.
00001 // Copyright 2012 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //     http://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include <stdio.h>
00016 #include <string.h>
00017 
00018 #include "util.h"
00019 #include "metrics.h"
00020 
00021 const char kPath[] =
00022     "../../third_party/WebKit/Source/WebCore/"
00023     "platform/leveldb/LevelDBWriteBatch.cpp";
00024 
00025 int main() {
00026   vector<int> times;
00027   string err;
00028 
00029   char buf[200];
00030   size_t len = strlen(kPath);
00031   strcpy(buf, kPath);
00032 
00033   for (int j = 0; j < 5; ++j) {
00034     const int kNumRepetitions = 2000000;
00035     int64_t start = GetTimeMillis();
00036     for (int i = 0; i < kNumRepetitions; ++i) {
00037       CanonicalizePath(buf, &len, &err);
00038     }
00039     int delta = (int)(GetTimeMillis() - start);
00040     times.push_back(delta);
00041   }
00042 
00043   int min = times[0];
00044   int max = times[0];
00045   float total = 0;
00046   for (size_t i = 0; i < times.size(); ++i) {
00047     total += times[i];
00048     if (times[i] < min)
00049       min = times[i];
00050     else if (times[i] > max)
00051       max = times[i];
00052   }
00053 
00054   printf("min %dms  max %dms  avg %.1fms\n",
00055          min, max, total / times.size());
00056 }