]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2015 Jakub Szuppe <j.szuppe@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 | ||
11 | #include <algorithm> | |
12 | #include <iostream> | |
13 | #include <vector> | |
14 | ||
15 | #include "perf.hpp" | |
16 | ||
17 | // Max integer that can be generated by rand_int() function. | |
18 | int rand_int_max = 25; | |
19 | ||
20 | int rand_int() | |
21 | { | |
22 | return static_cast<int>((rand() / double(RAND_MAX)) * rand_int_max); | |
23 | } | |
24 | ||
25 | int main(int argc, char *argv[]) | |
26 | { | |
27 | perf_parse_args(argc, argv); | |
28 | std::cout << "size: " << PERF_N << std::endl; | |
29 | ||
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); | |
33 | ||
34 | // trying to find element that isn't in vector (worst-case scenario) | |
35 | int wanted = rand_int_max + 1; | |
36 | ||
37 | // result | |
38 | std::vector<int>::iterator host_result_it; | |
39 | ||
40 | perf_timer t; | |
41 | for(size_t trial = 0; trial < PERF_TRIALS; trial++){ | |
42 | t.start(); | |
43 | host_result_it = std::find(host_vector.begin(), host_vector.end(), wanted); | |
44 | t.stop(); | |
45 | } | |
46 | std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; | |
47 | ||
48 | // verify | |
49 | if(host_result_it != host_vector.end()){ | |
50 | std::cout << "ERROR: " | |
51 | << "host_result_iterator != " | |
52 | << "host_vector.end()" | |
53 | << std::endl; | |
54 | return -1; | |
55 | } | |
56 | ||
57 | return 0; | |
58 | } |