Skip to content

Commit 908db7e

Browse files
committed
---
yaml --- r: 64616 b: refs/heads/snap-stage3 c: d9c0634 h: refs/heads/master v: v3
1 parent d13a98f commit 908db7e

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ca5ed4cc498ad5da22c6e1c4c0b79df07a07029e
4+
refs/heads/snap-stage3: d9c0634536c8ac6cd6309221b1bbd93517686aba
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/util.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,68 @@ mod tests {
195195
unsafe { assert_eq!(did_run, true); }
196196
}
197197
}
198+
199+
/// Completely miscellaneous language-construct benchmarks.
200+
#[cfg(test)]
201+
mod bench {
202+
203+
use extra::test::BenchHarness;
204+
use option::{Some,None};
205+
206+
// Static/dynamic method dispatch
207+
208+
struct Struct {
209+
field: int
210+
}
211+
212+
trait Trait {
213+
fn method(&self) -> int;
214+
}
215+
216+
impl Trait for Struct {
217+
fn method(&self) -> int {
218+
self.field
219+
}
220+
}
221+
222+
#[bench]
223+
fn trait_vtable_method_call(bh: &mut BenchHarness) {
224+
let s = Struct { field: 10 };
225+
let t = &s as &Trait;
226+
do bh.iter {
227+
t.method();
228+
}
229+
}
230+
231+
#[bench]
232+
fn trait_static_method_call(bh: &mut BenchHarness) {
233+
let s = Struct { field: 10 };
234+
do bh.iter {
235+
s.method();
236+
}
237+
}
238+
239+
// Overhead of various match forms
240+
241+
#[bench]
242+
fn match_option_some(bh: &mut BenchHarness) {
243+
let x = Some(10);
244+
do bh.iter {
245+
let _q = match x {
246+
Some(y) => y,
247+
None => 11
248+
};
249+
}
250+
}
251+
252+
#[bench]
253+
fn match_vec_pattern(bh: &mut BenchHarness) {
254+
let x = [1,2,3,4,5,6];
255+
do bh.iter {
256+
let _q = match x {
257+
[1,2,3,.._] => 10,
258+
_ => 11
259+
};
260+
}
261+
}
262+
}

0 commit comments

Comments
 (0)