1 //---------------------------------------------------------------------------// 2 // Copyright (c) 2013-2014 Rastko Anicic <anicic.rastko@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()17int rand_int() 18 { 19 return static_cast<int>(rand() % 10000000); 20 } 21 main(int argc,char * argv[])22int 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 int max = 0; 32 33 perf_timer t; 34 for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 35 t.start(); 36 max = *(std::max_element(host_vector.begin(), host_vector.end())); 37 t.stop(); 38 } 39 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 40 std::cout << "max: " << max << std::endl; 41 42 return 0; 43 } 44