]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/sample.cpp
1 // spreadsort 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/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 std::ifstream
input("input.txt", std::ios_base::in
| std::ios_base::binary
);
39 printf("input.txt could not be opened\n");
43 std::vector
<DATA_TYPE
> array
;
44 input
.seekg (0, std::ios_base::end
);
45 size_t length
= input
.tellg();
46 uCount
= length
/uSize
;
47 //Run multiple loops, if requested
48 for (unsigned u
= 0; u
< loopCount
; ++u
) {
49 input
.seekg (0, std::ios_base::beg
);
50 //Conversion to a vector
53 while (input
.good() && v
< uCount
)
54 input
.read(reinterpret_cast<char *>(&(array
[v
++])), uSize
);
61 std::sort(array
.begin(), array
.end());
63 boost::sort::spreadsort::spreadsort(array
.begin(), array
.end());
65 elapsed
= static_cast<double>(end
- start
);
68 ofile
.open("standard_sort_out.txt", std::ios_base::out
|
69 std::ios_base::binary
| std::ios_base::trunc
);
71 ofile
.open("boost_sort_out.txt", std::ios_base::out
|
72 std::ios_base::binary
| std::ios_base::trunc
);
74 for (unsigned v
= 0; v
< array
.size(); ++v
) {
75 ofile
.write(reinterpret_cast<char *>(&(array
[v
])), sizeof(array
[v
]) );
84 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
86 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);