profile_cxx11_lambda.cpp 1.2 KB

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