]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/test/path_times.cpp
import new upstream nautilus stable release 14.2.8
[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/config.hpp>
24 # if defined( BOOST_NO_STD_WSTRING )
25 # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
26 # endif
27
28 #include <boost/detail/lightweight_main.hpp>
29
30 namespace fs = boost::filesystem;
31 using namespace boost::timer;
32
33 #include <fstream>
34 #include <iostream>
35
36 using std::cout;
37 using std::endl;
38
39 namespace
40 {
41 boost::int64_t max_cycles;
42
43 template <class STD_STRING>
44 nanosecond_type time_ctor(const STD_STRING& s)
45 {
46 boost::timer::auto_cpu_timer tmr;
47 boost::int64_t count = 0;
48 do
49 {
50 fs::path p(s);
51 ++count;
52 } while (count < max_cycles);
53
54 boost::timer::cpu_times elapsed = tmr.elapsed();
55 return elapsed.user + elapsed.system;
56 }
57
58 nanosecond_type time_loop()
59 {
60 boost::timer::auto_cpu_timer tmr;
61 boost::int64_t count = 0;
62 do
63 {
64 ++count;
65 } while (count < max_cycles);
66
67 boost::timer::cpu_times elapsed = tmr.elapsed();
68 return elapsed.user + elapsed.system;
69 }
70 } // unnamed namespace
71
72 //--------------------------------------------------------------------------------------//
73 // main //
74 //--------------------------------------------------------------------------------------//
75
76 int cpp_main(int argc, char* argv[])
77 {
78 if (argc != 2)
79 {
80 cout << "Usage: path_times <cycles-in-millions>\n";
81 return 1;
82 }
83
84 max_cycles = std::atoi(argv[1]) * 1000000LL;
85 cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;
86
87 cout << "time_loop" << endl;
88 nanosecond_type x = time_loop();
89
90 cout << "time_ctor with string" << endl;
91 nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));
92
93 cout << "time_ctor with wstring" << endl;
94 nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
95
96 if (s > w)
97 cout << "narrow/wide CPU-time ratio = " << long double(s)/w << endl;
98 else
99 cout << "wide/narrow CPU-time ratio = " << long double(w)/s << endl;
100
101 cout << "returning from main()" << endl;
102 return 0;
103 }