Skip to content

Instantly share code, notes, and snippets.

@sehe
Last active November 3, 2015 00:06
Show Gist options
  • Save sehe/afd5dd924b4dc96d08dc to your computer and use it in GitHub Desktop.
Save sehe/afd5dd924b4dc96d08dc to your computer and use it in GitHub Desktop.
Bench real_generator with custom policies
all:test
CPPFLAGS+=-std=c++1y -Wall -pedantic
CPPFLAGS+=-g -O3 -DENABLE_ALL
#BOOST_DIR=/mnt/LARGE/MODULAR_BOOST/modular-boost
BOOST_DIR=/home/sehe/custom/boost
CPPFLAGS+=-isystem /home/sehe/custom/nonius/include
CPPFLAGS+=-isystem $(BOOST_DIR)
# CPPFLAGS+=-fopenmp
CPPFLAGS+=-pthread
CPPFLAGS+=-march=native
LDFLAGS+=-ltcmalloc
# CXX=g++-5
# CXX=/usr/lib/gcc-snapshot/bin/g++
# CC=/usr/lib/gcc-snapshot/bin/gcc
CXX=clang++-3.6 -stdlib=libc++
# CC=clang
%.S:%.cpp
$(CXX) $(CPPFLAGS) $^ -S -masm=intel -o - | egrep -v '\s*\.' | c++filt > $@
%.o:%.cpp
$(CXX) $(CPPFLAGS) $^ -c -o $@
%:%.o
$(CXX) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)
clock resolution: mean is 16.9593 ns (40960002 iterations)
benchmarking format_performance_karma
collecting 100 samples, 1 iterations each, in estimated 1899.3 μs
mean: 329.87 ns, lb 184.74 ns, ub 1038.61 ns, ci 0.95
std dev: 1413.34 ns, lb 24.7198 ns, ub 3.37159 μs, ci 0.95
found 24 outliers among 100 samples (24%)
variance is severely inflated by outliers
benchmarking format_performance_rule
collecting 100 samples, 81 iterations each, in estimated 1692.9 μs
mean: 215.823 ns, lb 212.939 ns, ub 221.624 ns, ci 0.95
std dev: 20.0933 ns, lb 11.484 ns, ub 33.58 ns, ci 0.95
found 11 outliers among 100 samples (11%)
variance is severely inflated by outliers
benchmarking format_performance_direct
collecting 100 samples, 88 iterations each, in estimated 1698.4 μs
mean: 169.203 ns, lb 168.598 ns, ub 170.905 ns, ci 0.95
std dev: 4.66986 ns, lb 1.61451 ns, ub 9.84715 ns, ci 0.95
found 7 outliers among 100 samples (7%)
variance is moderately inflated by outliers
benchmarking format_performance_direct_string
collecting 100 samples, 29 iterations each, in estimated 1748.7 μs
mean: 181.48 ns, lb 179.597 ns, ub 190.681 ns, ci 0.95
std dev: 18.3953 ns, lb 0.571537 ns, ub 43.8779 ns, ci 0.95
found 3 outliers among 100 samples (3%)
variance is severely inflated by outliers
benchmarking format_performance_direct_string_with_policy
collecting 100 samples, 97 iterations each, in estimated 1707.2 μs
mean: 173.642 ns, lb 171.737 ns, ub 179.564 ns, ci 0.95
std dev: 14.4068 ns, lb 0.28461 ns, ub 31.8642 ns, ci 0.95
found 3 outliers among 100 samples (3%)
variance is severely inflated by outliers
benchmarking format_performance_direct_string_with_policy15
collecting 100 samples, 42 iterations each, in estimated 1730.4 μs
mean: 413.133 ns, lb 411.407 ns, ub 419.013 ns, ci 0.95
std dev: 14.5309 ns, lb 4.95145 ns, ub 32.741 ns, ci 0.95
found 5 outliers among 100 samples (5%)
variance is moderately inflated by outliers
benchmarking format_performance_string
collecting 100 samples, 83 iterations each, in estimated 1701.5 μs
mean: 248.477 ns, lb 237.449 ns, ub 268.735 ns, ci 0.95
std dev: 73.8672 ns, lb 47.9677 ns, ub 136.175 ns, ci 0.95
found 2 outliers among 100 samples (2%)
variance is severely inflated by outliers
benchmarking format_performance_string_with_policy
collecting 100 samples, 88 iterations each, in estimated 1707.2 μs
mean: 196.386 ns, lb 194.168 ns, ub 201.986 ns, ci 0.95
std dev: 16.077 ns, lb 2.72801 ns, ub 29.5048 ns, ci 0.95
found 15 outliers among 100 samples (15%)
variance is severely inflated by outliers
benchmarking format_performance_string_with_policy15
collecting 100 samples, 37 iterations each, in estimated 1716.8 μs
mean: 470.97 ns, lb 461.662 ns, ub 486.695 ns, ci 0.95
std dev: 60.3921 ns, lb 40.0405 ns, ub 82.348 ns, ci 0.95
found 23 outliers among 100 samples (23%)
variance is severely inflated by outliers
benchmarking format_performance_boost_format
collecting 100 samples, 1 iterations each, in estimated 2.3852 ms
mean: 1355.26 ns, lb 1237.59 ns, ub 1932.57 ns, ci 0.95
std dev: 1151.34 ns, lb 10.5303 ns, ub 2.74733 μs, ci 0.95
found 4 outliers among 100 samples (4%)
variance is severely inflated by outliers
benchmarking format_performance_sprintf
collecting 100 samples, 1 iterations each, in estimated 3.2448 ms
mean: 606.86 ns, lb 550.63 ns, ub 880.83 ns, ci 0.95
std dev: 545.878 ns, lb 5.03809 ns, ub 1302.56 ns, ci 0.95
found 12 outliers among 100 samples (12%)
variance is severely inflated by outliers
benchmarking format_performance_iostreams
collecting 100 samples, 35 iterations each, in estimated 1718.5 μs
mean: 494.903 ns, lb 489.715 ns, ub 508.427 ns, ci 0.95
std dev: 37.1644 ns, lb 0.703666 ns, ub 74.11 ns, ci 0.95
found 6 outliers among 100 samples (6%)
variance is severely inflated by outliers
#include <boost/spirit/include/karma_auto.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/config/warning_disable.hpp>
#include <boost/format.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <nonius/benchmark.h++>
#include <nonius/main.h++>
namespace ka = boost::spirit::karma;
namespace {
template <typename T>
struct Scientific : ka::real_policies<T> {
using base_t = ka::real_policies<T>;
static inline constexpr int floatfield(T) { return base_t::fmtflags::scientific; }
};
template <typename BasePolicy, unsigned Precision>
struct WithPrecision : BasePolicy {
static inline constexpr unsigned precision(typename BasePolicy::value_type) { return Precision; }
};
typedef ka::real_generator<double, Scientific<double>> sc_double_type;
typedef ka::real_generator<double, WithPrecision<Scientific<double>, 15> > sc_double_type15;
static const sc_double_type sc_double = {};
static const sc_double_type15 sc_double15 = {};
inline constexpr double gen_input() { return 123456.123456; }
}
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_karma", [](auto cm)
{
char buffer[256];
cm.measure([&](int) {
char* p = buffer;
ka::generate(p, ka::double_, gen_input());
*p = '\0';
});
//std::cout << buffer << std::endl;
})
#endif
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_rule", [](auto cm)
{
ka::rule<char*, double()> const r = ka::double_;
char buffer[256];
cm.measure([&](int) {
char* p = buffer;
ka::generate(p, r, gen_input());
*p = '\0';
});
//std::cout << buffer << std::endl;
})
#endif
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_direct", [](auto cm)
{
using ka::real_inserter;
typedef real_inserter<double> inserter;
char buffer[256];
cm.measure([&](int) {
char* p = buffer;
inserter::call(p, gen_input());
*p = '\0';
});
//std::cout << buffer << std::endl;
})
#endif
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_direct_string", [](auto cm)
{
using ka::real_inserter;
typedef real_inserter<double> inserter;
char buffer[256];
std::string output;
cm.measure([&](int) {
output.clear();
char* p = buffer;
inserter::call(p, gen_input());
*p = '\0';
output = p;
});
//std::cout << buffer << std::endl;
})
#endif
NONIUS_BENCHMARK("format_performance_direct_string_with_policy", [](auto cm)
{
using ka::real_inserter;
typedef real_inserter<double, Scientific<double>> sc_inserter;
char buffer[256];
std::string output;
cm.measure([&](int) {
output.clear();
char* p = buffer;
sc_inserter::call(p, gen_input());
*p = '\0';
output = p;
});
//std::cout << buffer << std::endl;
})
NONIUS_BENCHMARK("format_performance_direct_string_with_policy15", [](auto cm)
{
using ka::real_inserter;
typedef real_inserter<double, WithPrecision<Scientific<double>, 15> > sc_inserter;
char buffer[256];
std::string output;
cm.measure([&](int) {
output.clear();
char* p = buffer;
sc_inserter::call(p, gen_input());
*p = '\0';
output = p;
});
//std::cout << buffer << std::endl;
})
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_string", [](auto cm)
{
std::string generated;
std::back_insert_iterator<std::string> sink(generated);
cm.measure([&](int) {
generated.clear();
ka::generate(sink, ka::double_, gen_input());
});
//std::cout << generated << std::endl;
})
#endif
NONIUS_BENCHMARK("format_performance_string_with_policy", [](auto cm)
{
std::string generated;
std::back_insert_iterator<std::string> sink(generated);
cm.measure([&](int) {
generated.clear();
ka::generate(sink, sc_double, gen_input());
});
//std::cout << generated << std::endl;
})
NONIUS_BENCHMARK("format_performance_string_with_policy15", [](auto cm)
{
std::string generated;
std::back_insert_iterator<std::string> sink(generated);
cm.measure([&](int) {
generated.clear();
ka::generate(sink, sc_double15, gen_input());
});
//std::cout << generated << std::endl;
})
// Boost.Format
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_boost_format", [](auto cm)
{
std::string generated;
boost::format double_format("%f");
cm.measure([&](int) {
generated = boost::str(double_format % gen_input());
});
//std::cout << strm.str() << std::endl;
})
#endif
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_sprintf", [](auto cm)
{
boost::timer t;
char buffer[256];
cm.measure([&](int) {
sprintf(buffer, "%f", gen_input());
});
//std::cout << buffer << std::endl;
})
#endif
#if ENABLE_ALL
NONIUS_BENCHMARK("format_performance_iostreams", [](auto cm)
{
std::stringstream strm;
cm.measure([&](int) {
strm.str("");
strm << gen_input();
});
//std::cout << strm.str() << std::endl;
})
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment