perf_stl_partial_sum.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #include <algorithm>
  11. #include <iostream>
  12. #include <numeric>
  13. #include <vector>
  14. #include <boost/compute/system.hpp>
  15. #include "perf.hpp"
  16. int rand_int()
  17. {
  18. return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
  19. }
  20. int main(int argc, char *argv[])
  21. {
  22. using boost::compute::int_;
  23. perf_parse_args(argc, argv);
  24. std::cout << "size: " << PERF_N << std::endl;
  25. // create vector of random numbers on the host
  26. std::vector<int_> v(PERF_N);
  27. std::vector<int_> r(PERF_N);
  28. perf_timer t;
  29. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  30. std::generate(v.begin(), v.end(), rand_int);
  31. t.start();
  32. std::partial_sum(
  33. v.begin(),
  34. v.end(),
  35. r.begin()
  36. );
  37. t.stop();
  38. }
  39. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  40. return 0;
  41. }