perf_stl_inner_product.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 "perf.hpp"
  15. int rand_int()
  16. {
  17. return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
  18. }
  19. int main(int argc, char *argv[])
  20. {
  21. perf_parse_args(argc, argv);
  22. std::cout << "size: " << PERF_N << std::endl;
  23. std::vector<int> h1(PERF_N);
  24. std::vector<int> h2(PERF_N);
  25. std::generate(h1.begin(), h1.end(), rand_int);
  26. std::generate(h2.begin(), h2.end(), rand_int);
  27. int product = 0;
  28. perf_timer t;
  29. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  30. t.start();
  31. product = std::inner_product(
  32. h1.begin(), h1.end(), h2.begin(), int(0)
  33. );
  34. t.stop();
  35. }
  36. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  37. std::cout << "product: " << product << std::endl;
  38. return 0;
  39. }