Skip to content

Commit 32080af

Browse files
committed
add benchmark shell for roaringbitmap64
1 parent dca219e commit 32080af

File tree

2 files changed

+340
-0
lines changed

2 files changed

+340
-0
lines changed

benchmark/benchmark_rb64.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
psql -f benchmark_rb64.sql $*>benchmark_rb64.log
4+
rc=$?
5+
6+
if [[ $rc -ne 0 ]]; then
7+
exit $rc
8+
fi
9+
10+
dbinfo=`psql $* -c "select now() now, extversion roaringbitmap,(select setting pg_version from pg_settings where name='server_version') from pg_extension where extname='roaringbitmap'"`
11+
12+
echo "$dbinfo"
13+
14+
echo '| No | test | time(ms) |'
15+
echo '| -- | ---- | -------- |'
16+
17+
count=0
18+
cat benchmark_rb64.log | while read line
19+
do
20+
if [[ $line =~ ^rb64_ ]]; then
21+
let count++
22+
echo -n "| $count | $line "
23+
elif [[ $line =~ 'Execution '[Tt]'ime: ' ]]; then
24+
array=($line)
25+
echo "| ${array[2]} |"
26+
fi
27+
done
28+
29+
grep "Total time" benchmark_rb64.log
30+

benchmark/benchmark_rb64.sql

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
set max_parallel_workers_per_gather=0;
2+
3+
\timing
4+
\echo create test table tb_test_bitmaps
5+
create temp table tb_test_bitmaps as
6+
select id,rb64_build_agg((random()*10000000)::int) bitmap
7+
from generate_series(1,100)id, generate_series(1,100000)b
8+
group by id;
9+
\timing
10+
11+
select now() time_start \gset
12+
13+
\echo rb64_and_1
14+
explain analyze
15+
with t as(
16+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
17+
)
18+
select rb64_and(ra1,ra2) from t,generate_series(1,100) id;
19+
20+
\echo rb64_and_2
21+
explain analyze
22+
with t as(
23+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
24+
)
25+
select rb64_and(ra1,ra2) from t,generate_series(1,1000) id;
26+
27+
\echo rb64_or_1
28+
explain analyze
29+
with t as(
30+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
31+
)
32+
select rb64_or(ra1,ra2) from t,generate_series(1,100) id;
33+
34+
\echo rb64_or_2
35+
explain analyze
36+
with t as(
37+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
38+
)
39+
select rb64_or(ra1,ra2) from t,generate_series(1,1000) id;
40+
41+
\echo rb64_xor_1
42+
explain analyze
43+
with t as(
44+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
45+
)
46+
select rb64_xor(ra1,ra2) from t,generate_series(1,100) id;
47+
48+
\echo rb64_xor_2
49+
explain analyze
50+
with t as(
51+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
52+
)
53+
select rb64_xor(ra1,ra2) from t,generate_series(1,1000) id;
54+
55+
\echo rb64_andnot_1
56+
explain analyze
57+
with t as(
58+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
59+
)
60+
select rb64_andnot(ra1,ra2) from t,generate_series(1,100) id;
61+
62+
\echo rb64_andnot_2
63+
explain analyze
64+
with t as(
65+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
66+
)
67+
select rb64_andnot(ra1,ra2) from t,generate_series(1,1000) id;
68+
69+
\echo rb64_add
70+
explain analyze
71+
with t as(
72+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
73+
)
74+
select rb64_add(ra1,id) from t,generate_series(1,1000)id;
75+
76+
\echo rb64_contains_1
77+
explain analyze
78+
with t as(
79+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
80+
)
81+
select rb64_contains(ra1,ra2) from t,generate_series(1,100);
82+
83+
\echo rb64_contains_2
84+
explain analyze
85+
with t as(
86+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
87+
)
88+
select rb64_contains(ra1,ra2) from t,generate_series(1,1000);
89+
90+
\echo rb64_contains_3
91+
explain analyze
92+
with t as(
93+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
94+
)
95+
select rb64_contains(ra1,id) from t,generate_series(1,1000)id;
96+
97+
\echo rb64_intersect_1
98+
explain analyze
99+
with t as(
100+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
101+
)
102+
select rb64_intersect(ra1,ra2) from t,generate_series(1,100) id;
103+
104+
\echo rb64_intersect_2
105+
explain analyze
106+
with t as(
107+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
108+
)
109+
select rb64_intersect(ra1,ra2) from t,generate_series(1,1000) id;
110+
111+
\echo rb64_equals_1
112+
explain analyze
113+
with t as(
114+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
115+
)
116+
select rb64_equals(ra1,ra2) from t,generate_series(1,100) id;
117+
118+
\echo rb64_equals_2
119+
explain analyze
120+
with t as(
121+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
122+
)
123+
select rb64_equals(ra1,ra2) from t,generate_series(1,1000) id;
124+
125+
\echo rb64_andnot_1
126+
explain analyze
127+
with t as(
128+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
129+
)
130+
select rb64_andnot(ra1,ra2) from t,generate_series(1,100) id;
131+
132+
\echo rb64_andnot_2
133+
explain analyze
134+
with t as(
135+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
136+
)
137+
select rb64_andnot(ra1,ra2) from t,generate_series(1,1000) id;
138+
139+
\echo rb64_index_1
140+
explain analyze
141+
with t as(
142+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
143+
)
144+
select rb64_index(ra1,id) from t,generate_series(1,1000)id;
145+
146+
\echo rb64_cardinality_1
147+
explain analyze
148+
with t as(
149+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
150+
)
151+
select rb64_cardinality(ra1) from t,generate_series(1,1000);
152+
153+
\echo rb64_and_cardinality_1
154+
explain analyze
155+
with t as(
156+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
157+
)
158+
select rb64_and_cardinality(ra1,ra2) from t,generate_series(1,100);
159+
160+
\echo rb64_and_cardinality_2
161+
explain analyze
162+
with t as(
163+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
164+
)
165+
select rb64_and_cardinality(ra1,ra2) from t,generate_series(1,1000);
166+
167+
\echo rb64_or_cardinality_1
168+
explain analyze
169+
with t as(
170+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
171+
)
172+
select rb64_or_cardinality(ra1,ra2) from t,generate_series(1,100);
173+
174+
\echo rb64_or_cardinality_2
175+
explain analyze
176+
with t as(
177+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
178+
)
179+
select rb64_or_cardinality(ra1,ra2) from t,generate_series(1,1000);
180+
181+
\echo rb64_xor_cardinality_1
182+
explain analyze
183+
with t as(
184+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
185+
)
186+
select rb64_xor_cardinality(ra1,ra2) from t,generate_series(1,100);
187+
188+
\echo rb64_xor_cardinality_2
189+
explain analyze
190+
with t as(
191+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
192+
)
193+
select rb64_xor_cardinality(ra1,ra2) from t,generate_series(1,1000);
194+
195+
\echo rb64_andnot_cardinality_1
196+
explain analyze
197+
with t as(
198+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
199+
)
200+
select rb64_andnot_cardinality(ra1,ra2) from t,generate_series(1,100);
201+
202+
\echo rb64_andnot_cardinality_2
203+
explain analyze
204+
with t as(
205+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
206+
)
207+
select rb64_andnot_cardinality(ra1,ra2) from t,generate_series(1,1000);
208+
209+
\echo rb64_is_empty_1
210+
explain analyze
211+
with t as(
212+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
213+
)
214+
select rb64_is_empty(ra1) from t,generate_series(1,1000);
215+
216+
\echo rb64_range_1
217+
explain analyze
218+
with t as(
219+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
220+
)
221+
select rb64_range(ra1,id,2000000) from t,generate_series(1,100)id;
222+
223+
\echo rb64_range_cardinality_1
224+
explain analyze
225+
with t as(
226+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
227+
)
228+
select rb64_range_cardinality(ra1,id,2000000) from t,generate_series(1,1000)id;
229+
230+
\echo rb64_min_1
231+
explain analyze
232+
with t as(
233+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
234+
)
235+
select rb64_min(ra1) from t,generate_series(1,1000);
236+
237+
\echo rb64_max_1
238+
explain analyze
239+
with t as(
240+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
241+
)
242+
select rb64_max(ra1) from t,generate_series(1,1000);
243+
244+
\echo rb64_rank_1
245+
explain analyze
246+
with t as(
247+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
248+
)
249+
select rb64_rank(ra1,100000+id) from t,generate_series(1,1000)id;
250+
251+
\echo rb64_jaccard_dist_1
252+
explain analyze
253+
with t as(
254+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,(select bitmap from tb_test_bitmaps where id=2 limit 1) ra2
255+
)
256+
select rb64_jaccard_dist(ra1,ra2) from t,generate_series(1,100);
257+
258+
\echo rb64_jaccard_dist_2
259+
explain analyze
260+
with t as(
261+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1,rb64_fill('{}'::roaringbitmap64,5000001,15000000) ra2
262+
)
263+
select rb64_jaccard_dist(ra1,ra2) from t,generate_series(1,1000);
264+
265+
\echo rb64_to_array_1
266+
explain analyze
267+
with t as(
268+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
269+
)
270+
select rb64_to_array(ra1) from t,generate_series(1,100);
271+
272+
\echo rb64_iterate_1
273+
explain analyze
274+
with t as(
275+
select (select bitmap from tb_test_bitmaps where id=1 limit 1) ra1
276+
)
277+
select rb64_iterate(ra1) from t,generate_series(1,10);
278+
279+
\echo rb64_build_agg_1
280+
explain analyze
281+
select rb64_build_agg(id) from generate_series(1,1000000) id;
282+
283+
\echo rb64_or_agg_1
284+
explain analyze
285+
select rb64_or_agg(bitmap) from tb_test_bitmaps;
286+
287+
\echo rb64_and_agg_1
288+
explain analyze
289+
select rb64_and_agg(bitmap) from tb_test_bitmaps;
290+
291+
\echo rb64_xor_agg_1
292+
explain analyze
293+
select rb64_xor_agg(bitmap) from tb_test_bitmaps;
294+
295+
\echo rb64_or_cardinality_agg_1
296+
explain analyze
297+
select rb64_or_cardinality_agg(bitmap) from tb_test_bitmaps;
298+
299+
\echo rb64_and_cardinality_agg_1
300+
explain analyze
301+
select rb64_and_cardinality_agg(bitmap) from tb_test_bitmaps;
302+
303+
\echo rb64_xor_cardinality_agg_1
304+
explain analyze
305+
select rb64_xor_cardinality_agg(bitmap) from tb_test_bitmaps;
306+
307+
select now() - :'time_start'::timestamp as time_escape \gset
308+
309+
\echo Total time: :time_escape
310+

0 commit comments

Comments
 (0)