Sha256: 6803feed470e335183ed0555bb9ba4d3de8ea4657d94cc45b8800becd90b0b00

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

// Copyright (c) 2018-2020 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/json/

#ifndef TAO_JSON_SRC_PERF_JSON_BENCH_MARK_HPP
#define TAO_JSON_SRC_PERF_JSON_BENCH_MARK_HPP

#include <chrono>
#include <cstddef>
#include <functional>
#include <iomanip>
#include <iostream>

namespace tao::bench
{
   inline std::uint64_t mark( const std::string& name, const std::string& type, const std::function< void() >& func, const std::uint64_t ref = 0 )
   {
      func();

      using clock = std::chrono::high_resolution_clock;

      for( std::uint64_t r = 0; r < 42; ++r ) {
         const std::uint64_t c = std::uint64_t( 1 ) << r;
         const auto start = clock::now();

         for( std::uint64_t i = 0; i < c; ++i ) {
            func();
         }
         const auto finish = clock::now();
         const std::uint64_t e = std::chrono::duration_cast< std::chrono::nanoseconds >( finish - start ).count();

         if( e > 1000000000 ) {
            const auto q = e / c;
            std::cout << "bench '" << std::setw( 10 ) << name << "' with '" << type << "':  iterations " << std::setw( 10 ) << c << "   elapsed " << std::setw( 10 ) << e << "   result " << std::setw( 10 ) << q << " nanos per iteration (" << ( ( 100 * q ) / ( bool( ref ) ? ref : q ) ) << "%)" << std::endl;
            return q;
         }
      }
      std::cout << " bench '" << name << "' did not complete" << std::endl;
      return 0;
   }

}  // namespace tao::bench

#endif

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
couchbase-3.0.0.alpha.4-x86_64-linux ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.4-x86_64-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.4-universal-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.4 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.3-x86_64-linux ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.3-x86_64-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.3-universal-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.3 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.2-x86_64-linux ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.2-x86_64-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.2-universal-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.2 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.1-x86_64-linux ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.1-x86_64-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.1-universal-darwin-19 ext/third_party/json/src/perf/json/bench_mark.hpp
couchbase-3.0.0.alpha.1 ext/third_party/json/src/perf/json/bench_mark.hpp