⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 process_perf_results.cpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 CPP
字号:
//  Copyright John Maddock 2007.//  Use, modification and distribution are subject to the//  Boost Software License, Version 1.0. (See accompanying file//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)#include <map>#include <fstream>#include <iostream>#include <boost/regex.hpp>#include <boost/lexical_cast.hpp>#include <boost/format.hpp>#include <boost/math/special_functions.hpp>std::map<std::string, double> results;std::map<std::string, std::string> extra_text;void load_file(std::string& s, std::istream& is){   s.erase();   if(is.bad()) return;   s.reserve(is.rdbuf()->in_avail());   char c;   while(is.get(c))   {      if(s.capacity() == s.size())         s.reserve(s.capacity() * 3);      s.append(1, c);   }}int main(int argc, const char* argv[]){   //   // Set any additional text that should accumpany specific results:   //   extra_text["msvc-dist-beta-R-quantile"] = "[footnote There are a small number of our test cases where the R library fails to converge on a result: these tend to dominate the performance result.]";   extra_text["msvc-dist-nbinom-R-quantile"] = "[footnote The R library appears to use a linear-search strategy, that can perform very badly in a small number of pathological cases, but may or may not be more efficient in \"typical\" cases]";   extra_text["gcc-4_2-dist-beta-R-quantile"] = "[footnote There are a small number of our test cases where the R library fails to converge on a result: these tend to dominate the performance result.]";   extra_text["gcc-4_2-dist-nbinom-R-quantile"] = "[footnote The R library appears to use a linear-search strategy, that can perform very badly in a small number of pathological cases, but may or may not be more efficient in \"typical\" cases]";   boost::regex e("^Testing\\s+(\\S+)\\s+(\\S+)");   std::string f;   for(int i = 1; i < argc-1; ++i)   {      std::ifstream is(argv[i]);      load_file(f, is);      boost::sregex_iterator a(f.begin(), f.end(), e), b;      while(a != b)      {         results[(*a).str(1)] = boost::lexical_cast<double>((*a).str(2));         ++a;      }   }   //   // Load quickbook file:   //   std::ifstream is(argv[argc-1]);   std::ofstream os(std::string(argv[argc-1]).append(".bak").c_str());   e.assign("\\[perf\\s+([^\\s.]+)(?:\\[[^\\]]*\\]|[^\\]])*\\]");   std::string newfile;   while(is.good())   {      std::getline(is, f);      os << f << std::endl;      boost::sregex_iterator i(f.begin(), f.end(), e), j;      double min = (std::numeric_limits<double>::max)();      while(i != j)      {         std::cout << (*i).str() << std::endl << (*i).str(1) << std::endl;         std::string item = (*i).str(1);         if(results.find(item) != results.end())         {            double r = results[item];            if(r < min)               min = r;         }         ++i;      }      //      // Now perform the substitutions:      //      std::string newstr;      std::string tail;      i = boost::sregex_iterator(f.begin(), f.end(), e);      while(i != j)      {         std::string item = (*i).str(1);         newstr.append(i->prefix());         if(results.find(item) != results.end())         {            double v = results[item];            double r = v / min;            newstr += std::string((*i)[0].first, (*i)[1].second);            newstr += "..[para ";            if(r < 1.01)               newstr += "*";            newstr += (boost::format("%.2f") % r).str();            if(r < 1.01)               newstr += "*";            if(extra_text.find(item) != extra_text.end())            {               newstr += extra_text[item];            }            newstr += "][para (";            newstr += (boost::format("%.3e") % results[item]).str();            newstr += "s)]]";         }         else         {            newstr.append(i->str());            std::cerr << "Item " << item << " not found!!" << std::endl;         }         tail = i->suffix();         ++i;      }      if(newstr.size())         newfile.append(newstr).append(tail);      else         newfile.append(f);      newfile.append("\n");   }   is.close();   std::ofstream ns(argv[argc-1]);   ns << newfile;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -