]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/alreadysorted.cpp
1 // spreadsort fully sorted data 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/spreadsort.hpp>
21 using namespace boost::sort::spreadsort
;
26 //Pass in an argument to test std::sort
27 int main(int argc
, const char ** argv
) {
28 size_t uCount
,uSize
=sizeof(DATA_TYPE
);
30 unsigned loopCount
= 1;
31 for (int u
= 1; u
< argc
; ++u
) {
32 if (std::string(argv
[u
]) == "-std")
35 loopCount
= atoi(argv
[u
]);
37 //Sorts the data once, then times sorting of already-sorted data
39 std::ifstream
input("input.txt", std::ios_base::in
| std::ios_base::binary
);
41 printf("input.txt could not be opened\n");
45 std::vector
<DATA_TYPE
> array
;
46 input
.seekg (0, std::ios_base::end
);
47 size_t length
= input
.tellg();
48 uCount
= length
/uSize
;
49 input
.seekg (0, std::ios_base::beg
);
50 //Conversion to a vector
53 while (input
.good() && v
< uCount
) // EOF or failure stops the reading
54 input
.read(reinterpret_cast<char *>(&(array
[v
++])), uSize
);
55 //Run multiple loops, if requested
56 for (unsigned u
= 0; u
< loopCount
; ++u
) {
61 //std::sort(&(array[0]), &(array[0]) + uCount);
62 std::sort(array
.begin(), array
.end());
65 //integer_sort(&(array[0]), &(array[0]) + uCount);
66 integer_sort(array
.begin(), array
.end());
69 elapsed
= static_cast<double>(end
- start
) ;
72 ofile
.open("standard_sort_out.txt", std::ios_base::out
|
73 std::ios_base::binary
| std::ios_base::trunc
);
75 ofile
.open("boost_sort_out.txt", std::ios_base::out
|
76 std::ios_base::binary
| std::ios_base::trunc
);
78 for (unsigned v
= 0; v
< array
.size(); ++v
) {
79 ofile
.write(reinterpret_cast<char *>(&(array
[v
])), sizeof(array
[v
]) );
87 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
89 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);