]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/local_function/example/profile_local_functor.cpp
2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/local_function
8 #include <boost/chrono.hpp>
12 #include "profile_helpers.hpp"
14 int main(int argc
, char* argv
[]) {
15 unsigned long size
= 0, trials
= 0;
16 profile::args(argc
, argv
, size
, trials
);
21 boost::chrono::system_clock::time_point start
=
22 boost::chrono::system_clock::now();
24 local_add(double& _sum
, const int& _factor
):
25 sum(_sum
), factor(_factor
) {}
26 inline void operator()(const double& num
) {
33 boost::chrono::duration
<double> decl_sec
=
34 boost::chrono::system_clock::now() - start
;
36 std::vector
<double> v(size
);
37 std::fill(v
.begin(), v
.end(), 1.0);
39 boost::chrono::duration
<double> trials_sec
;
40 for(unsigned long i
= 0; i
< trials
; ++i
) {
41 boost::chrono::system_clock::time_point start
=
42 boost::chrono::system_clock::now();
43 for(unsigned long j
= 0; j
< v
.size(); ++j
) add(v
[j
]); // No for_each.
44 trials_sec
+= boost::chrono::system_clock::now() - start
;
47 profile::display(size
, trials
, sum
, trials_sec
.count(), decl_sec
.count());