forked from boostorg/fusion
updates + zip tests
[SVN r36087]
This commit is contained in:
@ -14,12 +14,11 @@
|
||||
#include <boost/fusion/sequence/container/vector.hpp>
|
||||
#include <boost/fusion/sequence/container/list.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <functional>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/enum.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// inline aggressively
|
||||
@ -60,120 +59,105 @@ namespace
|
||||
|
||||
T sum;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void check(T const& seq, char const* info)
|
||||
{
|
||||
test::measure<accumulator<int> >(seq, 1);
|
||||
std::cout << info << test::live_code << std::endl;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void measure(T const& seq, char const* info, long const repeats)
|
||||
{
|
||||
std::cout
|
||||
<< info
|
||||
<< test::measure<accumulator<int> >(seq, repeats)
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// We'll initialize the sequences from numeric strings that
|
||||
// pass through boost::lexical_cast to make sure that the
|
||||
// compiler is not optimizing by replacing the computation
|
||||
// with constant results computed at compile time.
|
||||
#define INIT(z, n, text) boost::lexical_cast<int>(BOOST_PP_STRINGIZE(n))
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace test;
|
||||
using namespace boost::fusion;
|
||||
|
||||
std::cout.setf(std::ios::scientific);
|
||||
|
||||
vector<
|
||||
int, int, int
|
||||
>
|
||||
vsmall(BOOST_PP_ENUM_PARAMS(3,));
|
||||
vsmall(BOOST_PP_ENUM(3, INIT, _));
|
||||
|
||||
list<
|
||||
int, int, int
|
||||
>
|
||||
lsmall(BOOST_PP_ENUM_PARAMS(3,));
|
||||
lsmall(BOOST_PP_ENUM(3, INIT, _));
|
||||
|
||||
vector<
|
||||
int, int, int, int, int, int, int, int, int, int
|
||||
>
|
||||
vmid(BOOST_PP_ENUM_PARAMS(10,));
|
||||
vmedium(BOOST_PP_ENUM(10, INIT, _));
|
||||
|
||||
list<
|
||||
int, int, int, int, int, int, int, int, int, int
|
||||
>
|
||||
lmid(BOOST_PP_ENUM_PARAMS(10,));
|
||||
lmedium(BOOST_PP_ENUM(10, INIT, _));
|
||||
|
||||
vector<
|
||||
int, int, int, int, int, int, int, int, int, int
|
||||
, int, int, int, int, int, int, int, int, int, int
|
||||
, int, int, int, int, int, int, int, int, int, int
|
||||
>
|
||||
vbig(BOOST_PP_ENUM_PARAMS(30,));
|
||||
vbig(BOOST_PP_ENUM(30, INIT, _));
|
||||
|
||||
list<
|
||||
int, int, int, int, int, int, int, int, int, int
|
||||
, int, int, int, int, int, int, int, int, int, int
|
||||
, int, int, int, int, int, int, int, int, int, int
|
||||
>
|
||||
lbig(BOOST_PP_ENUM_PARAMS(30,));
|
||||
lbig(BOOST_PP_ENUM(30, INIT, _));
|
||||
|
||||
// first decide how many repetitions to measure
|
||||
long repeats = 100;
|
||||
double measured = 0;
|
||||
while (measured < 1.0 && repeats <= 10000000)
|
||||
while (measured < 2.0 && repeats <= 10000000)
|
||||
{
|
||||
repeats *= 10;
|
||||
|
||||
boost::timer time;
|
||||
|
||||
hammer<accumulator<int> >(vsmall, repeats);
|
||||
hammer<accumulator<int> >(lsmall, repeats);
|
||||
hammer<accumulator<int> >(vmid, repeats);
|
||||
hammer<accumulator<int> >(lmid, repeats);
|
||||
hammer<accumulator<int> >(vbig, repeats);
|
||||
hammer<accumulator<int> >(lbig, repeats);
|
||||
test::hammer<accumulator<int> >(vsmall, repeats);
|
||||
test::hammer<accumulator<int> >(lsmall, repeats);
|
||||
test::hammer<accumulator<int> >(vmedium, repeats);
|
||||
test::hammer<accumulator<int> >(lmedium, repeats);
|
||||
test::hammer<accumulator<int> >(vbig, repeats);
|
||||
test::hammer<accumulator<int> >(lbig, repeats);
|
||||
|
||||
measured = time.elapsed();
|
||||
}
|
||||
|
||||
measure<accumulator<int> >(vsmall, 1);
|
||||
std::cout
|
||||
<< "small vector accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
measure<accumulator<int> >(lsmall, 1);
|
||||
std::cout
|
||||
<< "small list accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
measure<accumulator<int> >(vmid, 1);
|
||||
std::cout
|
||||
<< "medium vector accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
measure<accumulator<int> >(lmid, 1);
|
||||
std::cout
|
||||
<< "medium list accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
measure<accumulator<int> >(vbig, 1);
|
||||
std::cout
|
||||
<< "big vector accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
measure<accumulator<int> >(lbig, 1);
|
||||
std::cout
|
||||
<< "big list accumulated result: "
|
||||
<< live_code << std::endl;
|
||||
check(vsmall, "small vector accumulated result: ");
|
||||
check(lsmall, "small list accumulated result: ");
|
||||
check(vmedium, "medium vector accumulated result: ");
|
||||
check(lmedium, "medium list accumulated result: ");
|
||||
check(vbig, "big vector accumulated result: ");
|
||||
check(lbig, "big list accumulated result: ");
|
||||
|
||||
std::cout.setf(std::ios::scientific);
|
||||
|
||||
std::cout
|
||||
<< "small vector time: "
|
||||
<< measure<accumulator<int> >(vsmall, repeats)
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< "small list time: "
|
||||
<< measure<accumulator<int> >(lsmall, repeats)
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< "medium vector time: "
|
||||
<< measure<accumulator<int> >(vmid, repeats)
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< "medium list time: "
|
||||
<< measure<accumulator<int> >(lmid, repeats)
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< "big vector time: "
|
||||
<< measure<accumulator<int> >(vbig, repeats)
|
||||
<< std::endl;
|
||||
std::cout
|
||||
<< "big list time: "
|
||||
<< measure<accumulator<int> >(lbig, repeats)
|
||||
<< std::endl;
|
||||
measure(vsmall, "small vector time: ", repeats);
|
||||
measure(lsmall, "small list time: ", repeats);
|
||||
measure(vmedium, "medium vector time: ", repeats);
|
||||
measure(lmedium, "medium list time: ", repeats);
|
||||
measure(vbig, "big vector time: ", repeats);
|
||||
measure(lbig, "big list time: ", repeats);
|
||||
|
||||
// This is ultimately responsible for preventing all the test code
|
||||
// from being optimized away. Change this to return 0 and you
|
||||
// unplug the whole test's life support system.
|
||||
return live_code != 0;
|
||||
return test::live_code != 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user