]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/sort/example/rightshiftsample.cpp
1 //! \brief Integer sort with a rightshift functor sorting example.
4 // Copyright Steven Ross 2009-2014.
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/sort for library home page.
12 // Caution: this file contains Quickbook markup as well as code
13 // and comments, don't change any of the special comment markups!
15 #include <boost/sort/spreadsort/spreadsort.hpp>
24 using namespace boost::sort::spreadsort
;
28 //[rightshift_int_functor
30 inline int operator()(DATA_TYPE x
, unsigned offset
) { return x
>> offset
; }
32 //] [/rightshift_int_functor]
34 //Pass in an argument to test std::sort
35 int main(int argc
, const char ** argv
) {
36 size_t uCount
,uSize
=sizeof(DATA_TYPE
);
38 unsigned loopCount
= 1;
39 for (int u
= 1; u
< argc
; ++u
) {
40 if (std::string(argv
[u
]) == "-std")
43 loopCount
= atoi(argv
[u
]);
45 std::ifstream
input("input.txt", std::ios_base::in
| std::ios_base::binary
);
47 printf("input.txt could not be opened\n");
51 std::vector
<DATA_TYPE
> array
;
52 input
.seekg (0, std::ios_base::end
);
53 size_t length
= input
.tellg();
54 uCount
= length
/uSize
;
55 //Run multiple loops, if requested
56 for (unsigned u
= 0; u
< loopCount
; ++u
) {
57 input
.seekg (0, std::ios_base::beg
);
58 //Conversion to a vector
61 while (input
.good() && v
< uCount
)
62 input
.read(reinterpret_cast<char *>(&(array
[v
++])), uSize
);
69 std::sort(array
.begin(), array
.end());
72 integer_sort(array
.begin(), array
.end(), rightshift());
76 elapsed
= static_cast<double>(end
- start
) ;
79 ofile
.open("standard_sort_out.txt", std::ios_base::out
|
80 std::ios_base::binary
| std::ios_base::trunc
);
82 ofile
.open("boost_sort_out.txt", std::ios_base::out
|
83 std::ios_base::binary
| std::ios_base::trunc
);
85 for (unsigned v
= 0; v
< array
.size(); ++v
) {
86 ofile
.write(reinterpret_cast<char *>(&(array
[v
])), sizeof(array
[v
]) );
94 printf("std::sort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);
96 printf("spreadsort elapsed time %f\n", total
/ CLOCKS_PER_SEC
);