Ninja
parser_perftest.cc
Go to the documentation of this file.
00001 // Copyright 2011 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 <stdlib.h>
00017 
00018 #include "depfile_parser.h"
00019 #include "util.h"
00020 #include "metrics.h"
00021 
00022 int main(int argc, char* argv[]) {
00023   if (argc < 2) {
00024     printf("usage: %s <file1> <file2...>\n", argv[0]);
00025     return 1;
00026   }
00027 
00028   vector<float> times;
00029   for (int i = 1; i < argc; ++i) {
00030     const char* filename = argv[i];
00031 
00032     for (int limit = 1 << 10; limit < (1<<20); limit *= 2) {
00033       int64_t start = GetTimeMillis();
00034       for (int rep = 0; rep < limit; ++rep) {
00035         string buf;
00036         string err;
00037         if (ReadFile(filename, &buf, &err) < 0) {
00038           printf("%s: %s\n", filename, err.c_str());
00039           return 1;
00040         }
00041 
00042         DepfileParser parser;
00043         if (!parser.Parse(&buf, &err)) {
00044           printf("%s: %s\n", filename, err.c_str());
00045           return 1;
00046         }
00047       }
00048       int64_t end = GetTimeMillis();
00049 
00050       if (end - start > 100) {
00051         int delta = (int)(end - start);
00052         float time = delta*1000 / (float)limit;
00053         printf("%s: %.1fus\n", filename, time);
00054         times.push_back(time);
00055         break;
00056       }
00057     }
00058   }
00059 
00060   if (!times.empty()) {
00061     float min = times[0];
00062     float max = times[0];
00063     float total = 0;
00064     for (size_t i = 0; i < times.size(); ++i) {
00065       total += times[i];
00066       if (times[i] < min)
00067         min = times[i];
00068       else if (times[i] > max)
00069         max = times[i];
00070     }
00071 
00072     printf("min %.1fus  max %.1fus  avg %.1fus\n",
00073            min, max, total / times.size());
00074   }
00075 
00076   return 0;
00077 }