perf_stl_partition_point.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. bool less_than_20(int value)
  20. {
  21. return value < 20;
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25. perf_parse_args(argc, argv);
  26. std::cout << "size: " << PERF_N << std::endl;
  27. // create vector of random numbers on the host
  28. std::vector<int> host_vector(PERF_N);
  29. std::generate(host_vector.begin(), host_vector.end(), rand_int);
  30. std::partition(host_vector.begin(), host_vector.end(),
  31. less_than_20);
  32. perf_timer t;
  33. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  34. t.start();
  35. std::partition_point(host_vector.begin(), host_vector.end(),
  36. less_than_20);
  37. t.stop();
  38. }
  39. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  40. return 0;
  41. }