profile_phoenix.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/spirit/home/phoenix/statement/sequence.hpp>
  7. #include <boost/spirit/home/phoenix/core/reference.hpp>
  8. #include <boost/spirit/home/phoenix/core/argument.hpp>
  9. #include <boost/spirit/home/phoenix/operator/arithmetic.hpp>
  10. #include <boost/chrono.hpp>
  11. #include <iostream>
  12. #include <vector>
  13. #include <algorithm>
  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. using boost::phoenix::ref;
  27. using boost::phoenix::arg_names::_1;
  28. std::for_each(v.begin(), v.end(), (
  29. ref(sum) += factor * _1
  30. ));
  31. trials_sec += boost::chrono::system_clock::now() - start;
  32. }
  33. profile::display(size, trials, sum, trials_sec.count());
  34. return 0;
  35. }