2 Copyright 2009 Kristian Nielsen
4 This file is part of BeeDB.
6 Foobar is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Foobar is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
22 Performance test for bitcopy().
25 #include "port/format_macros.h"
36 template<void (copier
)(uint64_t *, uint64_t, uint64_t *, uint64_t, uint64_t)>
37 class pf_bitcopy
: public perftest::test
{
39 pf_bitcopy(perftest
*tester
, const char *text
,
40 uint64_t src_pos
, uint64_t dst_pos
, uint64_t numbits
) :
41 test(tester
, "bitcopy", text
, param1_buf
, param2_buf
, numbits
),
42 src_pos(src_pos
), dst_pos(dst_pos
), numbits(numbits
)
44 memset(param1_buf
, 0, sizeof(param1_buf
));
45 snprintf(param1_buf
, sizeof(param1_buf
) - 1, "bits=%" PRIu64
, numbits
);
46 memset(param2_buf
, 0, sizeof(param2_buf
));
47 snprintf(param2_buf
, sizeof(param2_buf
) - 1,
48 "offs s=%" PRIu64
" d=%" PRIu64
, src_pos
, dst_pos
);
51 void run(uint64_t loops
);
62 template<void (copier
)(uint64_t *, uint64_t, uint64_t *, uint64_t, uint64_t)>
64 pf_bitcopy
<copier
>::run(uint64_t loops
)
66 uint64_t src_words
= (src_pos
+ numbits
+ 0x3f) >> 6;
67 uint64_t dst_words
= (dst_pos
+ numbits
+ 0x3f) >> 6;
68 uint64_t *src
= (uint64_t *)calloc(src_words
, sizeof(uint64_t));
69 uint64_t *dst
= (uint64_t *)malloc(src_words
* sizeof(uint64_t));
71 fatal_error("Out of memory");
75 for (uint64_t i
= loops
; i
> 0; i
--)
77 copier(dst
, dst_pos
, src
, src_pos
, numbits
);
83 Do something with buffer to discourage the compiler from optimising
87 for (uint64_t i
= dst_pos
; i
< dst_pos
+ numbits
; i
++)
89 value
^= dst
[i
>> 6] >> (i
& 0x3f);
98 main(int argc
, char *argv
[])
102 pf_bitcopy
<bitcopy
> t1(&tester
, "bitcopy", 17, 42, 17);
103 tester
.run_test(&t1
, 100000000);
104 pf_bitcopy
<bitcopy2
> t2(&tester
, "bitcopy2", 17, 42, 17);
105 tester
.run_test(&t2
, 100000000);
106 pf_bitcopy
<bitcopy3
> t3(&tester
, "bitcopy3", 17, 42, 17);
107 tester
.run_test(&t3
, 100000000);
109 pf_bitcopy
<bitcopy
> t4(&tester
, "bitcopy", 17, 42, 176);
110 tester
.run_test(&t4
, 100000000);
111 pf_bitcopy
<bitcopy2
> t5(&tester
, "bitcopy2", 17, 42, 176);
112 tester
.run_test(&t5
, 100000000);
113 pf_bitcopy
<bitcopy3
> t6(&tester
, "bitcopy3", 17, 42, 176);
114 tester
.run_test(&t6
, 100000000);
116 pf_bitcopy
<bitcopy
> t7(&tester
, "bitcopy", 17, 42, 17600);
117 tester
.run_test(&t7
, 1000000);
118 pf_bitcopy
<bitcopy2
> t8(&tester
, "bitcopy2", 17, 42, 17600);
119 tester
.run_test(&t8
, 1000000);
120 pf_bitcopy
<bitcopy3
> t9(&tester
, "bitcopy3", 17, 42, 17600);
121 tester
.run_test(&t9
, 1000000);
123 pf_bitcopy
<bitcopy
> t10(&tester
, "bitcopy", 17, 42, 1760000);
124 tester
.run_test(&t10
, 10000);
125 pf_bitcopy
<bitcopy2
> t11(&tester
, "bitcopy2", 17, 42, 1760000);
126 tester
.run_test(&t11
, 10000);
127 pf_bitcopy
<bitcopy3
> t12(&tester
, "bitcopy3", 17, 42, 1760000);
128 tester
.run_test(&t12
, 10000);