Skip to content

Commit 5bd8ab4

Browse files
committed
---
yaml --- r: 67197 b: refs/heads/master c: d9c0634 h: refs/heads/master i: 67195: e015495 v: v3
1 parent 2f6459f commit 5bd8ab4

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,5 +1,5 @@
11
---
2-
refs/heads/master: ca5ed4cc498ad5da22c6e1c4c0b79df07a07029e
2+
refs/heads/master: d9c0634536c8ac6cd6309221b1bbd93517686aba
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/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)