• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/config.hpp>
9 #ifdef BOOST_NO_CXX11_LAMBDAS
10 #   error "lambda functions required"
11 #else
12 
13 #include <boost/chrono.hpp>
14 #include <vector>
15 #include <algorithm>
16 #include <iostream>
17 #include "profile_helpers.hpp"
18 
main(int argc,char * argv[])19 int main(int argc, char* argv[]) {
20     unsigned long size = 0, trials = 0;
21     profile::args(argc, argv, size, trials);
22 
23     double sum = 0.0;
24     int factor = 1;
25 
26     std::vector<double> v(size);
27     std::fill(v.begin(), v.end(), 1.0);
28 
29     boost::chrono::duration<double> trials_sec;
30     for(unsigned long i = 0; i < trials; ++i) {
31         boost::chrono::system_clock::time_point start =
32                 boost::chrono::system_clock::now();
33         std::for_each(v.begin(), v.end(), [&sum, factor](const double& num) {
34             sum += factor * num;
35         });
36         trials_sec += boost::chrono::system_clock::now() - start;
37     }
38 
39     profile::display(size, trials, sum, trials_sec.count());
40     return 0;
41 }
42 
43 #endif // LAMBDAS
44 
45