]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/wstringsample.cpp
6775bbe7d162bee1c40f889f41c028149662922f
1 // spreadsort wstring sorting example
3 // Copyright Steven Ross 2009-2014.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/sort for library home page.
11 #include <boost/sort/spreadsort/string_sort.hpp>
21 using namespace boost::sort::spreadsort
;
23 #define DATA_TYPE wstring
25 //Pass in an argument to test std::sort
26 int main(int argc
, const char ** argv
) {
28 std::ofstream outfile
;
30 unsigned loopCount
= 1;
31 for (int u
= 1; u
< argc
; ++u
) {
32 if (std::string(argv
[u
]) == "-std")
35 loopCount
= atoi(argv
[u
]);
38 //Run multiple loops, if requested
39 std::vector
<DATA_TYPE
> array
;
40 for (unsigned u
= 0; u
< loopCount
; ++u
) {
41 indata
.open("input.txt", std::ios_base::in
| std::ios_base::binary
);
43 printf("input.txt could not be opened\n");
48 while (indata
.good()) {
49 indata
.read(reinterpret_cast<char *>(&inval
), sizeof(inval
));
50 current
.push_back(inval
);
51 //32 characters is a moderately long string
52 if (static_cast<int>(current
.size()) > inval
|| current
.size() >= 32) {
53 array
.push_back(current
);
57 //adding the last string
59 array
.push_back(current
);
65 wchar_t cast_type
= 0;
67 //std::sort(&(array[0]), &(array[0]) + uCount);
68 std::sort(array
.begin(), array
.end());
70 //string_sort(&(array[0]), &(array[0]) + uCount, cast_type);
71 string_sort(array
.begin(), array
.end(), cast_type
);
73 elapsed
= static_cast<double>(end
- start
);
75 outfile
.open("standard_sort_out.txt", std::ios_base::out
|
76 std::ios_base::binary
| std::ios_base::trunc
);
78 outfile
.open("boost_sort_out.txt", std::ios_base::out
|
79 std::ios_base::binary
| std::ios_base::trunc
);
81 for (unsigned u
= 0; u
< array
.size(); ++u
){
82 for (unsigned v
= 0; v
< array
[u
].size(); ++v
)
83 outfile
<< array
[u
][v
];
92 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
94 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);