当前位置: 首页>>代码示例>>C++>>正文


C++ Benchmark::GetRes方法代码示例

本文整理汇总了C++中Benchmark::GetRes方法的典型用法代码示例。如果您正苦于以下问题:C++ Benchmark::GetRes方法的具体用法?C++ Benchmark::GetRes怎么用?C++ Benchmark::GetRes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Benchmark的用法示例。


在下文中一共展示了Benchmark::GetRes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Shootout

void Shootout(const std::string &sCaption,
              std::vector<Benchmark*> vBenchmarks,
              std::vector<std::string> vExpr,
              int iCount,
              bool writeResultTable = false)
{
   char outstr[1024] = {0};
   char file  [1024] = {0};
   time_t t          = time(NULL);
   std::size_t excessive_failure_cnt = 0;

   sprintf(outstr, "Shootout_%%Y%%m%%d_%%H%%M%%S.txt");
   strftime(file, sizeof(file), outstr, localtime(&t));

   FILE* pRes = fopen(file, "w");
   assert(pRes);

   output(pRes, "Benchmark (Shootout for file \"%s\")\n", sCaption.c_str());

   Benchmark* pRefBench = vBenchmarks[0];

   std::map<double, std::vector<Benchmark*>> results;

   for (std::size_t i = 0; i < vExpr.size(); ++i)
   {
      std::size_t failure_count = 0;
      const std::string current_expr = vExpr[i];

      output(pRes, "\nExpression %d of %d: \"%s\"; Progress: ",
             (int)(i + 1),
             vExpr.size(),
             current_expr.c_str());

      double fRefResult = 0.0;
      double fRefSum    = 0.0;

      // Setup Reference parser result and total sum.
      {
         // Use the first as the reference parser.
         Benchmark *pBench = vBenchmarks[0];

         pBench->DoBenchmark(current_expr + " ", iCount);

         fRefResult = pBench->GetRes();
         fRefSum    = pBench->GetSum();

         pBench->IgnoreLastRate();

         if (
              (fRefResult ==  std::numeric_limits<double>::infinity()) ||
              (fRefResult == -std::numeric_limits<double>::infinity()) ||
              (fRefResult != fRefResult)
            )
         {
            output(pRes, "\nWARNING: Expression rejected due to non-numeric result.");
            continue;
         }
      }

      for (std::size_t j = 0; j < vBenchmarks.size(); ++j)
      {
         output(pRes, "#");  // <- "Progress" indicator for debugging, if a parser crashes we'd
                             //    like to know which one.

         Benchmark* pBench = vBenchmarks[j];

         std::string sExpr = current_expr;

         // Assign the current expression anew for each parser, furthermore preprocess the
         // expression string as some parsers use fancy characters to signal variables and
         // constants.
         pBench->PreprocessExpr(sExpr);

         double time = 1000000.0 * pBench->DoBenchmark(sExpr + " ", iCount);

         // The first parser is used for obtaining reference results.
         // If the reference result is a NaA the reference parser is
         // disqualified too.
         if (pBench->DidNotEvaluate())
         {
            pBench->AddFail(vExpr[i]);
            ++failure_count;
         }
         else if (
                   !is_equal(pBench->GetRes(),fRefResult)
                   ||
                   //Instead of 5, perhaps something proportional to iCount, but no less than 1?
                   (std::abs(static_cast<long long>(pBench->GetSum()) - static_cast<long long>(fRefSum)) > 5)
                 )
         {
            // Check the sum of all results and if the sum is ok,
            // check the last result of the benchmark run.
            pBench->AddFail(vExpr[i]);
            ++failure_count;
         }

         results[time].push_back(pBench);
      }

      output(pRes, "\n");
//.........这里部分代码省略.........
开发者ID:schoetbi,项目名称:math-parser-benchmark-project,代码行数:101,代码来源:ParserBench.cpp


注:本文中的Benchmark::GetRes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。