]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/context/performance/zeit.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / context / performance / zeit.hpp
1
2 // Copyright Oliver Kowalke 2009.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef ZEIT_H
8 #define ZEIT_H
9
10 #include <time.h>
11
12 #include <algorithm>
13 #include <numeric>
14 #include <cstddef>
15 #include <vector>
16
17 #include <boost/assert.hpp>
18 #include <boost/bind.hpp>
19 #include <boost/cstdint.hpp>
20
21 typedef boost::uint64_t zeit_t;
22
23 inline
24 zeit_t zeit()
25 {
26 timespec t;
27 ::clock_gettime( CLOCK_PROCESS_CPUTIME_ID, & t);
28 return t.tv_sec * 1000000000 + t.tv_nsec;
29 }
30
31 struct measure_zeit
32 {
33 zeit_t operator()()
34 {
35 zeit_t start( zeit() );
36 return zeit() - start;
37 }
38 };
39
40 inline
41 zeit_t overhead_zeit()
42 {
43 std::size_t iterations( 10);
44 std::vector< zeit_t > overhead( iterations, 0);
45 for ( std::size_t i( 0); i < iterations; ++i)
46 std::generate(
47 overhead.begin(), overhead.end(),
48 measure_zeit() );
49 BOOST_ASSERT( overhead.begin() != overhead.end() );
50 return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
51 }
52
53 #endif // ZEIT_H