Skip to content

Commit 40a16e7

Browse files
committed
---
yaml --- r: 69243 b: refs/heads/auto c: d9c0634 h: refs/heads/master i: 69241: 24b1af1 69239: aebe8e7 v: v3
1 parent f6b3945 commit 40a16e7

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
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: ca5ed4cc498ad5da22c6e1c4c0b79df07a07029e
17+
refs/heads/auto: d9c0634536c8ac6cd6309221b1bbd93517686aba
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/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)