]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/stringsample.cpp
1 // spreadsort string 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 string
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");
47 while (!indata
.eof() ) {
49 array
.push_back(inval
);
57 //std::sort(&(array[0]), &(array[0]) + uCount);
58 std::sort(array
.begin(), array
.end());
60 //string_sort(&(array[0]), &(array[0]) + uCount);
61 string_sort(array
.begin(), array
.end());
63 elapsed
= static_cast<double>(end
- start
);
65 outfile
.open("standard_sort_out.txt", std::ios_base::out
|
66 std::ios_base::binary
| std::ios_base::trunc
);
68 outfile
.open("boost_sort_out.txt", std::ios_base::out
|
69 std::ios_base::binary
| std::ios_base::trunc
);
71 for (unsigned u
= 0; u
< array
.size(); ++u
)
72 outfile
<< array
[u
] << "\n";
79 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
81 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);