• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@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 
rand_int()17 int rand_int()
18 {
19     return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
20 }
21 
main(int argc,char * argv[])22 int main(int argc, char *argv[])
23 {
24     perf_parse_args(argc, argv);
25     std::cout << "size: " << PERF_N << std::endl;
26 
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 
31     // count values equal to four in the vector
32     size_t count = 0;
33     perf_timer t;
34     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
35         t.start();
36         count = std::count(
37             host_vector.begin(), host_vector.end(), 4
38         );
39         t.stop();
40     }
41     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
42     std::cout << "count: " << count << std::endl;
43 
44     return 0;
45 }
46