spanset: add a benchmark of set operations

Summary: This would provide some data about changes around SpanSet.

Reviewed By: sfilipco

Differential Revision: D15023652

fbshipit-source-id: 4cff7d1876fe20cd876f26926f31e018b6c88fd9
This commit is contained in:
Jun Wu 2019-04-25 16:59:50 -07:00 committed by Facebook Github Bot
parent a611cbb0db
commit c6d9d5604b
2 changed files with 69 additions and 0 deletions

View File

@ -13,4 +13,9 @@ fs2 = "0.4.3"
tempfile = "3.0.7"
[dev-dependencies]
minibench = { path = "../minibench" }
quickcheck = "0.6"
[[bench]]
name = "spanset"
harness = false

View File

@ -0,0 +1,64 @@
// Copyright 2019 Facebook, Inc.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use dag::spanset::SpanSet;
use minibench::{bench, elapsed};
fn main() {
// Ruby code to generate random SpanSet:
// 119.times.map{rand(8)+1}.reduce([0]){|a,b|a+[b+a[-1]]}.each_slice(2).map{|x|"(#{x*','})"}.reverse*','
#[cfg_attr(rustfmt, rustfmt_skip)]
let span1 = SpanSet::from_sorted_spans(vec![
(557, 563), (549, 553), (545, 548), (530, 538), (523, 528), (513, 515),
(502, 509), (492, 496), (480, 488), (469, 475), (465, 466), (452, 460),
(440, 444), (433, 434), (431, 432), (422, 424), (416, 421), (405, 410),
(393, 400), (379, 385), (373, 376), (361, 365), (350, 356), (336, 343),
(325, 332), (317, 322), (308, 310), (299, 307), (290, 297), (285, 286),
(274, 278), (266, 272), (261, 263), (259, 260), (253, 257), (248, 251),
(239, 241), (227, 234), (220, 221), (204, 212), (193, 201), (180, 188),
(164, 172), (155, 157), (146, 147), (136, 144), (129, 135), (116, 121),
(105, 111), (94, 97), (89, 93), (75, 81), (60, 67), (51, 52), (35, 43),
(25, 30), (19, 20), (12, 13), (8, 10), (0, 6),
]);
#[cfg_attr(rustfmt, rustfmt_skip)]
let span2 = SpanSet::from_sorted_spans(vec![
(487, 491), (480, 486), (472, 475), (461, 465), (454, 460), (445, 446),
(439, 444), (425, 433), (416, 419), (413, 415), (408, 411), (396, 402),
(390, 395), (387, 389), (375, 382), (368, 371), (353, 360), (350, 352),
(342, 343), (340, 341), (333, 336), (328, 329), (326, 327), (318, 320),
(308, 312), (296, 302), (285, 293), (272, 277), (261, 268), (251, 258),
(236, 243), (224, 228), (214, 217), (208, 213), (199, 207), (193, 196),
(182, 185), (177, 179), (165, 170), (162, 164), (154, 161), (144, 151),
(142, 143), (138, 140), (130, 132), (124, 128), (117, 121), (112, 114),
(106, 111), (102, 105), (94, 98), (85, 91), (71, 78), (61, 68), (51, 54),
(38, 45), (26, 33), (16, 22), (6, 9), (0, 1),
]);
const N: usize = 10000;
bench("intersection", || {
elapsed(|| {
for _ in 0..N {
span1.intersection(&span2);
}
})
});
bench("union", || {
elapsed(|| {
for _ in 0..N {
span1.union(&span2);
}
})
});
bench("difference", || {
elapsed(|| {
for _ in 0..N {
span1.difference(&span2);
}
})
});
}