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