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 <numeric>
14 #include <vector>
15
16 #include "perf.hpp"
17
rand_int()18 int rand_int()
19 {
20 return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
21 }
22
main(int argc,char * argv[])23 int main(int argc, char *argv[])
24 {
25 perf_parse_args(argc, argv);
26 std::cout << "size: " << PERF_N << std::endl;
27
28 std::vector<int> h1(PERF_N);
29 std::vector<int> h2(PERF_N);
30 std::generate(h1.begin(), h1.end(), rand_int);
31 std::generate(h2.begin(), h2.end(), rand_int);
32
33 int product = 0;
34 perf_timer t;
35 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
36 t.start();
37 product = std::inner_product(
38 h1.begin(), h1.end(), h2.begin(), int(0)
39 );
40 t.stop();
41 }
42 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
43 std::cout << "product: " << product << std::endl;
44
45 return 0;
46 }
47