/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include <iostream>
#include <vector>
#include <string>

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>

#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/local_time/local_time.hpp>

#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

#include "string.hpp"
#include "locale.hpp"

using namespace std;
using namespace ds;

using namespace boost;
using namespace boost::lambda;
using namespace boost::posix_time;
using namespace boost::local_time;

typedef boost::split_iterator<string::iterator> string_split_iterator;

main(int argc, char *argv[]) {
    csv_string s;
    vector <csv_string> v;
    
    ptime start, stop;

    if (argc<2) {
	cout << argv[0] << " [file.csv]" << endl;
	abort();
    }
    
    
    std::ifstream f(argv[1]);
    if (!f) {
	cout << "Can't open input file " << argv[1] << endl;
	abort();
    }

	// configuring special locale
    std::locale loc(std::locale::classic(), new myctype<char>());
    
    while (std::getline(f, s, '\n'));	// caching

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	v = s.split(',');
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur0(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);
    
    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	v.clear();
	for (ds::split_iterator i = s.create_split_iterator(','); i!=ds::split_iterator(); ++i) {
	    v.push_back(*i);
	}
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur1(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	boost::split(v, s, boost::is_any_of(","));
	for_each(v.begin(), v.end(), bind(trim<string>, _1, std::locale()));
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur2(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	v.clear();
	for (string_split_iterator i = make_split_iterator(s, first_finder(",", is_equal())); i!=string_split_iterator(); ++i) {
	    v.push_back(trim_copy(copy_range<std::string>(*i)));
	}	
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur3(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	v.clear();
	for (string_split_iterator i = make_split_iterator(s, first_finder(",", is_equal())); i!=string_split_iterator(); ++i) {
	    string stmp;
	    trim_copy_if(back_inserter(stmp), *i, is_space());
	    v.push_back(stmp);
	}	
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur4(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);
    
    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	v.clear();
	for (string_split_iterator i = make_split_iterator(s, first_finder(",", is_equal())); i!=string_split_iterator(); ++i) {
            string::iterator tend = 
		boost::algorithm::detail::trim_end(begin(*i), end(*i), is_space());
            string::iterator tbegin = 
		boost::algorithm::detail::trim_begin(begin(*i), tend, is_space());
	    v.push_back(string(tbegin, tend));
	}	
//	cout << v[2] << "." << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur5(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
	string stmp;
	v.clear();

        std::istringstream ins (s);
	ins.imbue(loc);
	while (ins >> stmp) v.push_back(stmp);

//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur6(start, stop);    

    f.clear();			// forget we hit the end of file
    f.seekg(0, ios::beg);

    start = microsec_clock::local_time();
    while (std::getline(f, s, '\n')) {
        std::istringstream ins (s);
	ins.imbue(loc);
	istream_iterator<csv_string> start(ins);
	istream_iterator<csv_string> end;
	v = vector<csv_string>(start, end);
	
//	cout << v[0] << endl;
    }
    stop = microsec_clock::local_time();
    time_period cdur7(start, stop);    


    
    cout << "Own algorithm              : " << cdur0.length() << endl;
    cout << "Own algorithm (iter)       : " << cdur1.length() << endl;
    cout << "Boost stright forward      : " << cdur2.length() << endl;
    cout << "Boost optimized (1)        : " << cdur3.length() << endl;
    cout << "Boost optimized (2)        : " << cdur4.length() << endl;
    cout << "Boost optimized (3)        : " << cdur5.length() << endl;
    cout << "Overriding ctype facet (1) : " << cdur6.length() << " (*)" << endl;
    cout << "Overriding ctype facet (2) : " << cdur7.length() << " (*)" << endl;
    cout << endl << "(*) can read directly into the numericals, but triming should be worked out" << endl;
}