perf_stl_rotate_copy.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2014 Roshan <thisisroshansmail@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. // create vector of random numbers on the host
  24. std::vector<int> host_vector(PERF_N);
  25. std::generate(host_vector.begin(), host_vector.end(), rand_int);
  26. std::vector<int> host_vector2(PERF_N);
  27. perf_timer t;
  28. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  29. t.start();
  30. std::rotate_copy(host_vector.begin(), host_vector.begin()+(PERF_N/2), host_vector.end(), host_vector2.begin());
  31. t.stop();
  32. }
  33. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  34. return 0;
  35. }