Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / numeric / odeint / performance / rk_performance_test_case.hpp
1 /*
2  * rk_performance_test_case.hpp
3  *
4  * Copyright 2011-2012 Mario Mulansky
5  * Copyright 2012 Karsten Ahnert
6  *
7  * Distributed under the Boost Software License, Version 1.0.
8  * (See accompanying file LICENSE_1_0.txt or
9  * copy at http://www.boost.org/LICENSE_1_0.txt)
10  */
11
12
13 #include <iostream>
14 #include <boost/accumulators/accumulators.hpp>
15 #include <boost/accumulators/statistics.hpp>
16 #include <boost/timer.hpp>
17
18 #define tab "\t"
19
20 using namespace std;
21 using namespace boost::accumulators;
22
23 typedef accumulator_set<
24     double , stats< tag::mean , tag::variance >
25     > accumulator_type;
26
27 ostream& operator<<( ostream& out , accumulator_type &acc )
28 {
29     out << boost::accumulators::mean( acc ) << tab;
30 //    out << boost::accumulators::variance( acc ) << tab;
31     return out;
32 }
33
34 typedef boost::timer timer_type;
35
36
37 template< class Stepper >
38 void run( Stepper &stepper , const size_t num_of_steps = 20000000 , const double dt = 1E-10 )
39 {
40     const size_t loops = 20;
41
42     accumulator_type acc;
43     timer_type timer;
44
45     srand( 12312354 );
46
47     // transient
48     //stepper.reset_init_cond( );
49     //for( size_t i = 0 ; i < num_of_steps ; ++i )
50     //    stepper.do_step( dt );
51
52     for( size_t n=0 ; n<loops+1 ; ++n )
53     {
54         stepper.reset_init_cond( );
55
56         timer.restart();
57         for( size_t i = 0 ; i < num_of_steps ; ++i )
58             stepper.do_step( dt );
59         if( n>0 )
60         {   // take first run as transient
61             acc(timer.elapsed());
62             clog.precision(8);
63             clog.width(10);
64             clog << acc << " " << stepper.state(0) << endl;
65         }
66     }
67     cout << acc << endl;
68 }