1
2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/local_function
7
8 #include <boost/local_function.hpp>
9 #include <boost/chrono.hpp>
10 #include <vector>
11 #include <algorithm>
12 #include <iostream>
13 #include "profile_helpers.hpp"
14
main(int argc,char * argv[])15 int main(int argc, char* argv[]) {
16 unsigned long size = 0, trials = 0;
17 profile::args(argc, argv, size, trials);
18
19 double sum = 0.0;
20 int factor = 1;
21
22 boost::chrono::system_clock::time_point start =
23 boost::chrono::system_clock::now();
24 void BOOST_LOCAL_FUNCTION(
25 const double& num, bind& sum, const bind& factor) {
26 sum += factor * num;
27 } BOOST_LOCAL_FUNCTION_NAME(add)
28 boost::chrono::duration<double> decl_sec =
29 boost::chrono::system_clock::now() - start;
30
31 std::vector<double> v(size);
32 std::fill(v.begin(), v.end(), 1.0);
33
34 boost::chrono::duration<double> trials_sec;
35 for(unsigned long i = 0; i < trials; ++i) {
36 boost::chrono::system_clock::time_point start =
37 boost::chrono::system_clock::now();
38 std::for_each(v.begin(), v.end(), add);
39 trials_sec += boost::chrono::system_clock::now() - start;
40 }
41
42 profile::display(size, trials, sum, trials_sec.count(), decl_sec.count());
43 return 0;
44 }
45
46