]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/perf/perf_stl_find.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2015 Jakub Szuppe <j.szuppe@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
17 // Max integer that can be generated by rand_int() function.
18 int rand_int_max
= 25;
22 return static_cast<int>((rand() / double(RAND_MAX
)) * rand_int_max
);
25 int main(int argc
, char *argv
[])
27 perf_parse_args(argc
, argv
);
28 std::cout
<< "size: " << PERF_N
<< std::endl
;
30 // create vector of random numbers on the host
31 std::vector
<int> host_vector(PERF_N
);
32 std::generate(host_vector
.begin(), host_vector
.end(), rand_int
);
34 // trying to find element that isn't in vector (worst-case scenario)
35 int wanted
= rand_int_max
+ 1;
38 std::vector
<int>::iterator host_result_it
;
41 for(size_t trial
= 0; trial
< PERF_TRIALS
; trial
++){
43 host_result_it
= std::find(host_vector
.begin(), host_vector
.end(), wanted
);
46 std::cout
<< "time: " << t
.min_time() / 1e6
<< " ms" << std::endl
;
49 if(host_result_it
!= host_vector
.end()){
50 std::cout
<< "ERROR: "
51 << "host_result_iterator != "
52 << "host_vector.end()"