File: path_times.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (97 lines) | stat: -rw-r--r-- 2,530 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//  Boost Filesystem path_times.cpp  ---------------------------------------------------//

//  Copyright Beman Dawes 2013

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

//  Library home page: http://www.boost.org/libs/filesystem

#include <boost/config/warning_disable.hpp>

#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif

#include <boost/timer/timer.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/cstdint.hpp>

#include <boost/detail/lightweight_main.hpp>

namespace fs = boost::filesystem;
using namespace boost::timer;

#include <fstream>
#include <iostream>

using std::cout;
using std::endl;

namespace {
boost::int64_t max_cycles;

template< class STD_STRING >
nanosecond_type time_ctor(const STD_STRING& s)
{
    boost::timer::auto_cpu_timer tmr;
    boost::int64_t count = 0;
    do
    {
        fs::path p(s);
        ++count;
    } while (count < max_cycles);

    boost::timer::cpu_times elapsed = tmr.elapsed();
    return elapsed.user + elapsed.system;
}

nanosecond_type time_loop()
{
    boost::timer::auto_cpu_timer tmr;
    boost::int64_t count = 0;
    do
    {
        ++count;
    } while (count < max_cycles);

    boost::timer::cpu_times elapsed = tmr.elapsed();
    return elapsed.user + elapsed.system;
}
} // unnamed namespace

//--------------------------------------------------------------------------------------//
//                                      main                                            //
//--------------------------------------------------------------------------------------//

int cpp_main(int argc, char* argv[])
{
    if (argc != 2)
    {
        cout << "Usage: path_times <cycles-in-millions>\n";
        return 1;
    }

    max_cycles = std::atoi(argv[1]) * 1000000LL;
    cout << "testing " << std::atoi(argv[1]) << " million cycles" << endl;

    cout << "time_loop" << endl;
    nanosecond_type x = time_loop();

    cout << "time_ctor with string" << endl;
    nanosecond_type s = time_ctor(std::string("/foo/bar/baz"));

    cout << "time_ctor with wstring" << endl;
    nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));

    if (s > w)
        cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
    else
        cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;

    cout << "returning from main()" << endl;
    return 0;
}