]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/path_times.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / filesystem / test / path_times.cpp
1 // Boost Filesystem path_times.cpp ---------------------------------------------------//
2
3 // Copyright Beman Dawes 2013
4
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
7
8 // Library home page: http://www.boost.org/libs/filesystem
9
10 #include <boost/config/warning_disable.hpp>
11
12 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
13 #define BOOST_FILESYSTEM_NO_DEPRECATED
14 #endif
15 #ifndef BOOST_SYSTEM_NO_DEPRECATED
16 #define BOOST_SYSTEM_NO_DEPRECATED
17 #endif
18
19 #include <boost/timer/timer.hpp>
20 #include <boost/filesystem/path.hpp>
21 #include <boost/cstdint.hpp>
22
23 #include <boost/detail/lightweight_main.hpp>
24
25 namespace fs = boost::filesystem;
26 using namespace boost::timer;
27
28 #include <fstream>
29 #include <iostream>
30
31 using std::cout;
32 using std::endl;
33
34 namespace {
35 boost::int64_t max_cycles;
36
37 template< class STD_STRING >
38 nanosecond_type time_ctor(const STD_STRING& s)
39 {
40 boost::timer::auto_cpu_timer tmr;
41 boost::int64_t count = 0;
42 do
43 {
44 fs::path p(s);
45 ++count;
46 } while (count < max_cycles);
47
48 boost::timer::cpu_times elapsed = tmr.elapsed();
49 return elapsed.user + elapsed.system;
50 }
51
52 nanosecond_type time_loop()
53 {
54 boost::timer::auto_cpu_timer tmr;
55 boost::int64_t count = 0;
56 do
57 {
58 ++count;
59 } while (count < max_cycles);
60
61 boost::timer::cpu_times elapsed = tmr.elapsed();
62 return elapsed.user + elapsed.system;
63 }
64 } // unnamed namespace
65
66 //--------------------------------------------------------------------------------------//
67 // main //
68 //--------------------------------------------------------------------------------------//
69
70 int cpp_main(int argc, char* argv[])
71 {
72 if (argc != 2)
73 {
74 cout << "Usage: path_times <cycles-in-millions>\n";
75 return 1;
76 }
77
78 max_cycles = std::atoi(argv[1]) * 1000000LL;
79 cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
80
81 cout << "time_loop" << endl;
82 nanosecond_type x = time_loop();
83
84 cout << "time_ctor with string" << endl;
85 nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
86
87 cout << "time_ctor with wstring" << endl;
88 nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
89
90 if (s > w)
91 cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
92 else
93 cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;
94
95 cout << "returning from main()" << endl;
96 return 0;
97 }