perf_stl_max_element.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Rastko Anicic <anicic.rastko@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 <vector>
  13. #include "perf.hpp"
  14. int rand_int()
  15. {
  16. return static_cast<int>(rand() % 10000000);
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. perf_parse_args(argc, argv);
  21. std::cout << "size: " << PERF_N << std::endl;
  22. // create vector of random numbers on the host
  23. std::vector<int> host_vector(PERF_N);
  24. std::generate(host_vector.begin(), host_vector.end(), rand_int);
  25. int max = 0;
  26. perf_timer t;
  27. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  28. t.start();
  29. max = *(std::max_element(host_vector.begin(), host_vector.end()));
  30. t.stop();
  31. }
  32. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  33. std::cout << "max: " << max << std::endl;
  34. return 0;
  35. }