mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Initial performance tests.
This commit is contained in:
134
reporting/performance/Jamfile.v2
Normal file
134
reporting/performance/Jamfile.v2
Normal file
@@ -0,0 +1,134 @@
|
||||
# Copyright Daryle Walker, Hubert Holin, John Maddock 2006 - 2007
|
||||
# copyright Paul A. Bristow 2006 - 2010
|
||||
# Distributed under 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.
|
||||
# \math_toolkit\libs\math\test\jamfile.v2
|
||||
# Runs all math toolkit tests, functions & distributions,
|
||||
# and build math examples.
|
||||
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
import modules ;
|
||||
import path ;
|
||||
import pch ;
|
||||
import ../../../config/checks/config : requires ;
|
||||
using quickbook ;
|
||||
using auto-index ;
|
||||
|
||||
project
|
||||
: requirements
|
||||
<include>../../include_private
|
||||
;
|
||||
|
||||
if $(is_unix)
|
||||
{
|
||||
local osname = [ SHELL uname ] ;
|
||||
|
||||
switch $(osname)
|
||||
{
|
||||
case "Sun*" : OTHERFLAGS = "-lpthread -lrt" ;
|
||||
case "*BSD*" : OTHERFLAGS = "-lpthread" ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Configuration first:
|
||||
#
|
||||
lib gsl ;
|
||||
lib gslcblas ;
|
||||
lib Rmath ;
|
||||
obj has_libstdcxx_tr1 : has_libstdcxx_tr1.cpp ;
|
||||
explicit has_libstdcxx_tr1 ;
|
||||
obj has_c99_cmath : has_c99_cmath.cpp ;
|
||||
explicit has_c99_cmath ;
|
||||
exe has_gsl : has_gsl.cpp gsl gslcblas ;
|
||||
explicit has_gsl ;
|
||||
exe has_rmath : has_rmath.cpp Rmath ;
|
||||
explicit has_rmath ;
|
||||
|
||||
CEPHES_SOURCE = acosh.c airy.c asin.c asinh.c atan.c atanh.c bdtr.c beta.c
|
||||
btdtr.c cbrt.c chbevl.c chdtr.c clog.c cmplx.c const.c
|
||||
cosh.c dawsn.c drand.c ei.c ellie.c ellik.c ellpe.c ellpj.c ellpk.c
|
||||
exp.c exp10.c exp2.c expn.c expx2.c fabs.c fac.c fdtr.c
|
||||
fresnl.c gamma.c gdtr.c hyp2f1.c hyperg.c i0.c i1.c igami.c incbet.c
|
||||
incbi.c igam.c isnan.c iv.c j0.c j1.c jn.c jv.c k0.c k1.c kn.c kolmogorov.c
|
||||
log.c log2.c log10.c lrand.c nbdtr.c ndtr.c ndtri.c pdtr.c planck.c
|
||||
polevl.c polmisc.c polylog.c polyn.c pow.c powi.c psi.c rgamma.c round.c
|
||||
shichi.c sici.c sin.c sindg.c sinh.c spence.c stdtr.c struve.c
|
||||
tan.c tandg.c tanh.c unity.c yn.c zeta.c zetac.c
|
||||
sqrt.c floor.c setprec.c mtherr.c ;
|
||||
|
||||
path-constant here : . ;
|
||||
make $(here)/third_party/cephes_double/acosh.c : : @check_exists ;
|
||||
actions check_exists
|
||||
{
|
||||
stat $(<)
|
||||
}
|
||||
explicit $(here)/third_party/cephes_double/acosh.c ;
|
||||
|
||||
lib cephes_double : $(here)/third_party/cephes_double/$(CEPHES_SOURCE)
|
||||
:
|
||||
release
|
||||
<link>static
|
||||
[ check-target-builds $(here)/third_party/cephes_double/acosh.c : : <build>no ]
|
||||
;
|
||||
|
||||
explicit cephes_double ;
|
||||
|
||||
obj table_helper : table_helper.cpp ;
|
||||
|
||||
rule all-tests {
|
||||
local result ;
|
||||
for local source in [ glob test*.cpp ]
|
||||
{
|
||||
}
|
||||
|
||||
#
|
||||
# Special cases to test different compiler options:
|
||||
#
|
||||
result += [ run test_cbrt.cpp /boost/regex//boost_regex /boost/system /boost/chrono /boost/filesystem table_helper
|
||||
: : : debug <toolset>msvc [ check-target-builds ../accuracy//has_c99_cmath : <define>TEST_C99 : ] : test_cbrt_msvc_debug ] ;
|
||||
result += [ run test_cbrt.cpp /boost/regex//boost_regex /boost/system /boost/chrono /boost/filesystem table_helper
|
||||
: : : release <address-model>32 <toolset>msvc [ check-target-builds ../accuracy//has_c99_cmath : <define>TEST_C99 : ] : test_cbrt_msvc_release_32 ] ;
|
||||
result += [ run test_cbrt.cpp /boost/regex//boost_regex /boost/system /boost/chrono /boost/filesystem table_helper
|
||||
: : : release <address-model>64 <toolset>msvc <cxxflags>-arch:SSE2 [ check-target-builds ../accuracy//has_c99_cmath : <define>TEST_C99 : ] : test_cbrt_msvc_release_64 ] ;
|
||||
result += [ run test_cbrt.cpp /boost/regex//boost_regex /boost/system /boost/chrono /boost/filesystem table_helper
|
||||
: : : release <address-model>64 <cxxflags>-arch:AVX <toolset>msvc [ check-target-builds ../accuracy//has_c99_cmath : <define>TEST_C99 : ] : test_cbrt_msvc_release_64_avx ] ;
|
||||
|
||||
return $(result) ;
|
||||
}
|
||||
|
||||
test-suite report_gen : [ all-tests ] ;
|
||||
|
||||
path-constant images_location : html ;
|
||||
path-constant here : . ;
|
||||
|
||||
xml report : doc/report.qbk : <dependency>report_gen ;
|
||||
boostbook standalone
|
||||
:
|
||||
report
|
||||
:
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../../..
|
||||
|
||||
# Some general style settings:
|
||||
<xsl:param>table.footnote.number.format=1
|
||||
<xsl:param>footnote.number.format=1
|
||||
<xsl:param>html.stylesheet=http://www.boost.org/doc/libs/1_58_0/doc/src/boostbook.css
|
||||
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=0
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=2
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=4
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=10
|
||||
;
|
||||
|
||||
34
reporting/performance/doc/performance_tables.qbk
Normal file
34
reporting/performance/doc/performance_tables.qbk
Normal file
@@ -0,0 +1,34 @@
|
||||
[/Cell Content:]
|
||||
[template cl_arch_ia32_Ox_x64_build_Microsoft_Visual_C_version_12_0Win32[]62ns]
|
||||
[template boost_math_cbrtcl_arch_ia32_Ox_x64_build_Microsoft_Visual_C_version_12_0Win32[]45ns]
|
||||
[template cl_arch_sse2_Ox_x86_build_Microsoft_Visual_C_version_12_0Win32[]68ns]
|
||||
[template boost_math_cbrtcl_arch_sse2_Ox_x86_build_Microsoft_Visual_C_version_12_0Win32[]64ns]
|
||||
[template cl_Od_x86_build_Microsoft_Visual_C_version_12_0Win32[]201ns]
|
||||
[template boost_math_cbrtcl_Od_x86_build_Microsoft_Visual_C_version_12_0Win32[]262ns]
|
||||
|
||||
[/tables:]
|
||||
|
||||
[template table_cbrt[]
|
||||
[table:table_cbrt Performance comparison for cbrt
|
||||
[[Function][cl /Od (x86 build)][cl /arch:sse2 /Ox (x86 build)][cl /arch:ia32 /Ox (x64 build)]]
|
||||
[[boost::math::cbrt][[role green 86ns]][[role green 2ns]][[role green 32ns]]]
|
||||
[[::cbrt][[role green 86ns]][[role green 2ns]][[role green 32ns]]]
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
[/sections:]
|
||||
|
||||
[template section_cbrt[]
|
||||
[section:section_cbrt cbrt]
|
||||
[table_cbrt]
|
||||
[endsect]
|
||||
]
|
||||
|
||||
[template all_sections[]
|
||||
[section_cbrt]
|
||||
]
|
||||
|
||||
[template all_tables[]
|
||||
[table_cbrt]
|
||||
]
|
||||
15
reporting/performance/doc/report.qbk
Normal file
15
reporting/performance/doc/report.qbk
Normal file
@@ -0,0 +1,15 @@
|
||||
[article Special Function Error Rates Report
|
||||
[quickbook 1.6]
|
||||
[/purpose ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22]
|
||||
[license
|
||||
Distributed under 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])
|
||||
]
|
||||
]
|
||||
|
||||
[import performance_tables.qbk]
|
||||
[import ../../../doc/html4_symbols.qbk]
|
||||
|
||||
[all_sections]
|
||||
|
||||
131
reporting/performance/html/index.html
Normal file
131
reporting/performance/html/index.html
Normal file
@@ -0,0 +1,131 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Special Function Error Rates Report</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/1_58_0/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="index.html" title="Special Function Error Rates Report">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"></div>
|
||||
<div class="article">
|
||||
<div class="titlepage">
|
||||
<div>
|
||||
<div><h2 class="title">
|
||||
<a name="special_function_error_rates_rep"></a>Special Function Error Rates Report</h2></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="special_function_error_rates_rep.legal"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></div>
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl><dt><span class="section"><a href="index.html#special_function_error_rates_rep.section_cbrt">cbrt</a></span></dt></dl>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="special_function_error_rates_rep.section_cbrt"></a><a class="link" href="index.html#special_function_error_rates_rep.section_cbrt" title="cbrt">cbrt</a>
|
||||
</h2></div></div></div>
|
||||
<div class="table">
|
||||
<a name="special_function_error_rates_rep.section_cbrt.table_cbrt"></a><p class="title"><b>Table 1. Performance comparison for cbrt</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Performance comparison for cbrt">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Function
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
cl /Od (x86 build)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
cl /arch:sse2 /Ox (x86 build)
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
cl /arch:ia32 /Ox (x64 build)
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
boost::math::cbrt
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">86ns</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">2ns</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">32ns</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
::cbrt
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">86ns</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">2ns</span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="green">32ns</span>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: July 09, 2015 at 18:35:13 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"></div>
|
||||
</body>
|
||||
</html>
|
||||
103
reporting/performance/performance.hpp
Normal file
103
reporting/performance/performance.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// Copyright John Maddock 2015.
|
||||
// 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)
|
||||
|
||||
#ifndef PERFORMANCE_HPP
|
||||
#define PERFORMANCE_HPP
|
||||
|
||||
#include <boost/math/special_functions/relative_difference.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/chrono.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
template <class Array>
|
||||
void add_data(const Array& a)
|
||||
{
|
||||
//
|
||||
// This function is called multiple times to merge multiple data sets into one big table:
|
||||
//
|
||||
for(typename Array::const_iterator i = a.begin(); i != a.end(); ++i)
|
||||
{
|
||||
data.push_back(std::vector<double>());
|
||||
for(typename Array::value_type::const_iterator j = i->begin(); j != i->end(); ++j)
|
||||
{
|
||||
data.back().push_back(*j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class Func, class Result>
|
||||
void screen_data(Func f, Result r)
|
||||
{
|
||||
//
|
||||
// If any of the implementations being tested produces garbage for one of our
|
||||
// test cases (or else if we test a domain they don't support), then we remove that
|
||||
// row from the table. This allows us to only test a common supported sub-set for performance:
|
||||
//
|
||||
for(std::vector<std::vector<double> >::size_type row = 0; row < data.size(); ++row)
|
||||
{
|
||||
try
|
||||
{
|
||||
double computed = f(data[row]);
|
||||
double expected = r(data[row]);
|
||||
double err = boost::math::relative_difference(computed, expected);
|
||||
if(err > 1e-7)
|
||||
{
|
||||
data.erase(data.begin() + row);
|
||||
--row;
|
||||
}
|
||||
}
|
||||
catch(const std::exception&)
|
||||
{
|
||||
data.erase(data.begin() + row);
|
||||
--row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class Clock>
|
||||
struct stopwatch
|
||||
{
|
||||
typedef typename Clock::duration duration;
|
||||
stopwatch()
|
||||
{
|
||||
m_start = Clock::now();
|
||||
}
|
||||
duration elapsed()
|
||||
{
|
||||
return Clock::now() - m_start;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
m_start = Clock::now();
|
||||
}
|
||||
|
||||
private:
|
||||
typename Clock::time_point m_start;
|
||||
};
|
||||
|
||||
double sum = 0;
|
||||
|
||||
template <class Func>
|
||||
double exec_timed_test(Func& f)
|
||||
{
|
||||
double t = 0;
|
||||
unsigned repeats = 1;
|
||||
do{
|
||||
stopwatch<boost::chrono::high_resolution_clock> w;
|
||||
|
||||
for(unsigned count = 0; count < repeats; ++count)
|
||||
{
|
||||
for(std::vector<std::vector<double> >::const_iterator i = data.begin(); i != data.end(); ++i)
|
||||
sum += f(*i);
|
||||
}
|
||||
|
||||
t = boost::chrono::duration_cast<boost::chrono::duration<double>>(w.elapsed()).count();
|
||||
if(t < 0.5)
|
||||
repeats *= 2;
|
||||
} while(t < 0.5);
|
||||
return t / (repeats * data.size());
|
||||
}
|
||||
|
||||
#endif // PERFORMANCE_HPP
|
||||
410
reporting/performance/table_helper.cpp
Normal file
410
reporting/performance/table_helper.cpp
Normal file
@@ -0,0 +1,410 @@
|
||||
// Copyright John Maddock 2015.
|
||||
// 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)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning (disable : 4224)
|
||||
#endif
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/interprocess/sync/named_mutex.hpp>
|
||||
#include <boost/interprocess/sync/scoped_lock.hpp>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include "table_helper.hpp"
|
||||
|
||||
std::vector<std::vector<double> > data;
|
||||
|
||||
inline std::string sanitize_string(const std::string& s)
|
||||
{
|
||||
static const boost::regex e("[^a-zA-Z0-9]+");
|
||||
std::string result = boost::regex_replace(s, e, "_");
|
||||
while(result[0] == '_')
|
||||
result.erase(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::string content;
|
||||
boost::filesystem::path path_to_content;
|
||||
|
||||
struct content_loader
|
||||
{
|
||||
boost::interprocess::named_mutex mu;
|
||||
boost::interprocess::scoped_lock<boost::interprocess::named_mutex> lock;
|
||||
content_loader() : mu(boost::interprocess::open_or_create, "handle_test_result"), lock(mu)
|
||||
{
|
||||
boost::filesystem::path p(__FILE__);
|
||||
p = p.parent_path();
|
||||
p /= "doc";
|
||||
p /= "performance_tables.qbk";
|
||||
path_to_content = p;
|
||||
if(boost::filesystem::exists(p))
|
||||
{
|
||||
boost::filesystem::ifstream is(p);
|
||||
if(is.good())
|
||||
{
|
||||
do
|
||||
{
|
||||
char c = static_cast<char>(is.get());
|
||||
if(c != EOF)
|
||||
content.append(1, c);
|
||||
} while(is.good());
|
||||
}
|
||||
}
|
||||
}
|
||||
~content_loader()
|
||||
{
|
||||
boost::filesystem::ofstream os(path_to_content);
|
||||
os << content;
|
||||
}
|
||||
void instantiate()const
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static const content_loader loader;
|
||||
|
||||
void load_table(std::vector<std::vector<std::string> >& table, std::string::const_iterator begin, std::string::const_iterator end)
|
||||
{
|
||||
static const boost::regex item_e(
|
||||
"\\["
|
||||
"([^\\[\\]]*(?0)?)*"
|
||||
"\\]"
|
||||
);
|
||||
|
||||
boost::regex_token_iterator<std::string::const_iterator> i(begin, end, item_e), j;
|
||||
|
||||
while(i != j)
|
||||
{
|
||||
// Add a row:
|
||||
table.push_back(std::vector<std::string>());
|
||||
boost::regex_token_iterator<std::string::const_iterator> k(i->first + 1, i->second - 1, item_e);
|
||||
while(k != j)
|
||||
{
|
||||
// Add a cell:
|
||||
table.back().push_back(std::string(k->first + 1, k->second - 1));
|
||||
++k;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
std::string save_table(std::vector<std::vector<std::string> >& table)
|
||||
{
|
||||
std::string result;
|
||||
|
||||
static const boost::regex value_e("\\d+");
|
||||
|
||||
std::vector<boost::uintmax_t> best_values(table[0].size(), (std::numeric_limits<boost::uintmax_t>::max)());
|
||||
|
||||
for(unsigned i = 1; i < table[0].size(); ++i)
|
||||
{
|
||||
for(unsigned k = 1; k < table.size(); ++k)
|
||||
{
|
||||
boost::smatch what;
|
||||
if(regex_search(table[k][i], what, value_e))
|
||||
{
|
||||
boost::uintmax_t val = boost::lexical_cast<boost::uintmax_t>(what.str());
|
||||
if(val < best_values[i])
|
||||
best_values[i] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(std::vector<std::vector<std::string> >::const_iterator i = table.begin(), j = table.end(); i != j; ++i)
|
||||
{
|
||||
result += "[";
|
||||
for(std::vector<std::string>::const_iterator k = i->begin(), l = i->end(); k != l; ++k)
|
||||
{
|
||||
result += "[";
|
||||
if((i == table.begin()) || (k == i->begin()))
|
||||
{
|
||||
result += *k;
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::smatch what;
|
||||
if(regex_search(*k, what, value_e))
|
||||
{
|
||||
boost::uintmax_t val = boost::lexical_cast<boost::uintmax_t>(what.str());
|
||||
bool have_role = false;
|
||||
if(val < 1.2 * best_values[k - i->begin()])
|
||||
{
|
||||
have_role = true;
|
||||
result += "[role green ";
|
||||
}
|
||||
else if(val > 2 * best_values[k - i->begin()])
|
||||
{
|
||||
have_role = true;
|
||||
result += "[role red ";
|
||||
}
|
||||
result += boost::lexical_cast<std::string>(val);
|
||||
result += "ns";
|
||||
if(have_role)
|
||||
result += "]";
|
||||
}
|
||||
else
|
||||
result += *k;
|
||||
}
|
||||
result += "]";
|
||||
}
|
||||
result += "]\n";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void add_to_all_sections(const std::string& id, std::string list_name)
|
||||
{
|
||||
std::string::size_type pos = content.find("[template " + list_name + "[]"), end_pos;
|
||||
if(pos == std::string::npos)
|
||||
{
|
||||
//
|
||||
// Just append to the end:
|
||||
//
|
||||
content.append("\n[template ").append(list_name).append("[]\n[").append(id).append("]\n]\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Read in the all list of sections, add our new one (in alphabetical order),
|
||||
// and then rewrite the whole thing:
|
||||
//
|
||||
static const boost::regex item_e(
|
||||
"\\["
|
||||
"([^\\[\\]]*(?0)?)*"
|
||||
"\\]|\\]"
|
||||
);
|
||||
boost::regex_token_iterator<std::string::const_iterator> i(content.begin() + pos + 12 + list_name.size(), content.end(), item_e), j;
|
||||
std::set<std::string> sections;
|
||||
while(i != j)
|
||||
{
|
||||
if(i->length() == 1)
|
||||
{
|
||||
end_pos = i->first - content.begin();
|
||||
break;
|
||||
}
|
||||
sections.insert(std::string(i->first + 1, i->second - 1));
|
||||
++i;
|
||||
}
|
||||
sections.insert(id);
|
||||
std::string new_list = "\n";
|
||||
for(std::set<std::string>::const_iterator sec = sections.begin(); sec != sections.end(); ++sec)
|
||||
{
|
||||
new_list += "[" + *sec + "]\n";
|
||||
}
|
||||
content.replace(pos + 12 + list_name.size(), end_pos - pos - 12 - list_name.size(), new_list);
|
||||
}
|
||||
}
|
||||
|
||||
void add_cell(const std::string& cell_name, const std::string& table_name, const std::string& row_name, const std::string& column_heading)
|
||||
{
|
||||
//
|
||||
// Load the table, add our data, and re-write:
|
||||
//
|
||||
std::string table_id = "table_" + sanitize_string(table_name);
|
||||
boost::regex table_e("\\[table:" + table_id
|
||||
+ "\\s[^\\[]+"
|
||||
"((\\["
|
||||
"([^\\[\\]]*(?2)?)*"
|
||||
"\\]\\s*)*\\s*)"
|
||||
"\\]"
|
||||
);
|
||||
|
||||
boost::smatch table_location;
|
||||
if(regex_search(content, table_location, table_e))
|
||||
{
|
||||
std::vector<std::vector<std::string> > table_data;
|
||||
load_table(table_data, table_location[1].first, table_location[1].second);
|
||||
//
|
||||
// Figure out which column we're on:
|
||||
//
|
||||
unsigned column_id = 1001u;
|
||||
for(unsigned i = 0; i < table_data[0].size(); ++i)
|
||||
{
|
||||
if(table_data[0][i] == column_heading)
|
||||
{
|
||||
column_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(column_id > 1000)
|
||||
{
|
||||
//
|
||||
// Need a new column, must be adding a new compiler to the table!
|
||||
//
|
||||
table_data[0].push_back(column_heading);
|
||||
for(unsigned i = 1; i < table_data.size(); ++i)
|
||||
table_data[i].push_back(std::string());
|
||||
column_id = table_data[0].size() - 1;
|
||||
}
|
||||
//
|
||||
// Figure out the row:
|
||||
//
|
||||
unsigned row_id = 1001;
|
||||
for(unsigned i = 1; i < table_data.size(); ++i)
|
||||
{
|
||||
if(table_data[i][0] == row_name)
|
||||
{
|
||||
row_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(row_id > 1000)
|
||||
{
|
||||
//
|
||||
// Need a new row, add it now:
|
||||
//
|
||||
table_data.push_back(std::vector<std::string>());
|
||||
table_data.back().push_back(row_name);
|
||||
for(unsigned i = 1; i < table_data[0].size(); ++i)
|
||||
table_data.back().push_back(std::string());
|
||||
row_id = table_data.size() - 1;
|
||||
}
|
||||
//
|
||||
// Update the entry:
|
||||
//
|
||||
std::string& s = table_data[row_id][column_id];
|
||||
if(s.empty())
|
||||
{
|
||||
std::cout << "Adding " << cell_name << " to empty cell.";
|
||||
s = "[" + cell_name + "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cell_name.find("_boost_") != std::string::npos)
|
||||
{
|
||||
std::cout << "Adding " << cell_name << " to start of cell.";
|
||||
s.insert(0, "[" + cell_name + "][br][br]");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Adding " << cell_name << " to end of cell.";
|
||||
if((s.find("_boost_") != std::string::npos) && (s.find("[br]") == std::string::npos))
|
||||
s += "[br]"; // extra break if we're adding directly after the boost results.
|
||||
s += "[br][" + cell_name + "]";
|
||||
}
|
||||
}
|
||||
//
|
||||
// Convert back to a string and insert into content:
|
||||
std::string c = save_table(table_data);
|
||||
content.replace(table_location.position(1), table_location.length(1), c);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Create a new table and try again:
|
||||
//
|
||||
std::string new_table = "\n[template " + table_id;
|
||||
new_table += "[]\n[table:" + table_id;
|
||||
new_table += " Performance comparison for ";
|
||||
new_table += table_name;
|
||||
new_table += "\n[[Function][";
|
||||
new_table += column_heading;
|
||||
new_table += "]]\n";
|
||||
new_table += "[[";
|
||||
new_table += row_name;
|
||||
new_table += "][[";
|
||||
new_table += cell_name;
|
||||
new_table += "]]]\n]\n]\n";
|
||||
|
||||
std::string::size_type pos = content.find("[/tables:]");
|
||||
if(pos != std::string::npos)
|
||||
content.insert(pos + 10, new_table);
|
||||
else
|
||||
content += "\n\n[/tables:]\n" + new_table;
|
||||
//
|
||||
// Add a section for this table as well:
|
||||
//
|
||||
std::string section_id = "section_" + sanitize_string(table_name);
|
||||
if(content.find(section_id + "[]") == std::string::npos)
|
||||
{
|
||||
std::string new_section = "\n[template " + section_id + "[]\n[section:" + section_id + " " + table_name + "]\n[" + table_id + "]\n[endsect]\n]\n";
|
||||
pos = content.find("[/sections:]");
|
||||
if(pos != std::string::npos)
|
||||
content.insert(pos + 12, new_section);
|
||||
else
|
||||
content += "\n\n[/sections:]\n" + new_section;
|
||||
add_to_all_sections(section_id);
|
||||
}
|
||||
//
|
||||
// Add to list of all tables (not in sections):
|
||||
//
|
||||
add_to_all_sections(table_id, "all_tables");
|
||||
}
|
||||
}
|
||||
|
||||
void set_result(const std::string& cell_name, const std::string& cell_content, const std::string& table_name, const std::string& row_name, const std::string& column_name)
|
||||
{
|
||||
loader.instantiate();
|
||||
const boost::regex e("\\[template\\s+" + cell_name +
|
||||
"\\[\\]([^\\n]*)\\]$");
|
||||
|
||||
boost::smatch what;
|
||||
if(regex_search(content, what, e))
|
||||
{
|
||||
content.replace(what.position(1), what.length(1), cell_content);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Need to add new content:
|
||||
std::string::size_type pos = content.find("[/Cell Content:]");
|
||||
std::string t = "\n[template " + cell_name + "[] " + cell_content + "]";
|
||||
if(pos != std::string::npos)
|
||||
content.insert(pos + 16, t);
|
||||
else
|
||||
{
|
||||
content.insert(0, t);
|
||||
content.insert(0, "[/Cell Content:]");
|
||||
}
|
||||
}
|
||||
//
|
||||
// Check to verify that our content is actually used somewhere,
|
||||
// if not we need to create a place for it:
|
||||
//
|
||||
if(content.find("[" + cell_name + "]") == std::string::npos)
|
||||
add_cell(cell_name, table_name, row_name, column_name);
|
||||
}
|
||||
|
||||
|
||||
void report_execution_time_multi_compilation(double t, std::string function_group, std::string function, std::string compilation)
|
||||
{
|
||||
std::string cell_name = sanitize_string(function) + sanitize_string(compilation) + sanitize_string(BOOST_COMPILER) + sanitize_string(BOOST_PLATFORM);
|
||||
std::string cell_content = boost::lexical_cast<std::string>(static_cast<boost::uintmax_t>(t / 1e-9));
|
||||
cell_content += "ns";
|
||||
std::string table_name = function_group;
|
||||
std::string row_name = function;
|
||||
std::string column_name = compilation;
|
||||
set_result(cell_name, cell_content, table_name, row_name, column_name);
|
||||
}
|
||||
|
||||
std::string get_compiler_options_name()
|
||||
{
|
||||
#if defined(BOOST_MSVC)
|
||||
std::string result;
|
||||
#ifdef _DEBUG
|
||||
result = "cl /Od";
|
||||
#elif defined(__AVX2__)
|
||||
result = "cl /arch:AVX2 /Ox";
|
||||
#elif defined(__AVX__)
|
||||
result = "cl /arch:AVX /Ox";
|
||||
#elif _M_IX86_FP == 2
|
||||
result = "cl /arch:sse2 /Ox";
|
||||
#else
|
||||
result = "cl /arch:ia32 /Ox";
|
||||
#endif
|
||||
#ifdef _M_AMD64
|
||||
result += " (x64 build)";
|
||||
#else
|
||||
result += " (x86 build)";
|
||||
#endif
|
||||
return result;
|
||||
#else
|
||||
return "Unknown";
|
||||
#endif
|
||||
}
|
||||
|
||||
24
reporting/performance/table_helper.hpp
Normal file
24
reporting/performance/table_helper.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright John Maddock 2015.
|
||||
// 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)
|
||||
|
||||
#ifndef TABLE_HELPER_HPP
|
||||
#define TABLE_HELPER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
extern std::vector<std::vector<double> > data;
|
||||
|
||||
std::string sanitize_string(const std::string& s);
|
||||
void load_table(std::vector<std::vector<std::string> >& table, std::string::const_iterator begin, std::string::const_iterator end);
|
||||
std::string save_table(std::vector<std::vector<std::string> >& table);
|
||||
void add_to_all_sections(const std::string& id, std::string list_name = "all_sections");
|
||||
void add_cell(const std::string& cell_name, const std::string& table_name, const std::string& row_name, const std::string& column_heading);
|
||||
void set_result(const std::string& cell_name, const std::string& cell_content, const std::string& table_name, const std::string& row_name, const std::string& column_name);
|
||||
void report_execution_time_multi_compilation(double t, std::string function_group, std::string function, std::string compilation);
|
||||
std::string get_compiler_options_name();
|
||||
|
||||
#endif // TABLE_HELPER_HPP
|
||||
|
||||
44
reporting/performance/test_cbrt.cpp
Normal file
44
reporting/performance/test_cbrt.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright John Maddock 2015.
|
||||
// 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)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning (disable : 4224)
|
||||
#endif
|
||||
|
||||
#include <boost/math/special_functions/cbrt.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include "../../test/table_type.hpp"
|
||||
#include "table_helper.hpp"
|
||||
#include "performance.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef double T;
|
||||
#define SC_(x) static_cast<double>(x)
|
||||
# include "../../test/cbrt_data.ipp"
|
||||
|
||||
add_data(cbrt_data);
|
||||
|
||||
|
||||
screen_data([](const std::vector<double>& v){ return boost::math::cbrt(v[1]); }, [](const std::vector<double>& v){ return v[0]; });
|
||||
|
||||
#ifdef TEST_C99
|
||||
screen_data([](const std::vector<double>& v){ return ::cbrt(v[1]); }, [](const std::vector<double>& v){ return v[0]; });
|
||||
#endif
|
||||
|
||||
double time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cbrt(v[1]); });
|
||||
report_execution_time_multi_compilation(time, "cbrt", "boost::math::cbrt", get_compiler_options_name());
|
||||
std::cout << time << std::endl;
|
||||
#ifdef TEST_C99
|
||||
time = exec_timed_test([](const std::vector<double>& v){ return ::cbrt(v[1]); });
|
||||
std::cout << time << std::endl;
|
||||
report_execution_time_multi_compilation(time, "cbrt", "::cbrt", get_compiler_options_name());
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user