]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/random/performance/nondet_random_speed.cpp
1 /* boost nondet_random_speed.cpp performance test
3 * Copyright Jens Maurer 2000
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
14 #include <boost/timer.hpp>
15 #include <boost/random/random_device.hpp>
17 // set to your CPU frequency
18 static const double cpu_frequency
= 1.87 * 1e9
;
20 static void show_elapsed(double end
, int iter
, const std::string
& name
)
22 double usec
= end
/iter
*1e6
;
23 double cycles
= usec
* cpu_frequency
/1e6
;
24 std::cout
<< name
<< ": "
25 << usec
*1e3
<< " nsec/loop = "
26 << cycles
<< " CPU cycles"
30 template<class Result
, class RNG
>
31 static void timing(RNG
& rng
, int iter
, const std::string
& name
)
33 volatile Result tmp
; // make sure we're not optimizing too much
35 for(int i
= 0; i
< iter
; i
++)
37 show_elapsed(t
.elapsed(), iter
, name
);
41 void run(int iter
, const std::string
& name
)
44 timing
<long>(rng
, iter
, name
);
47 int main(int argc
, char*argv
[])
50 std::cerr
<< "usage: " << argv
[0] << " iterations" << std::endl
;
54 int iter
= std::atoi(argv
[1]);
56 boost::random::random_device dev
;
57 timing
<unsigned int>(dev
, iter
, "random_device");