Skip to content

Fix issue12118: Return value/use extra::test::black_box in benchmarks that are optimised to nothing #12212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ mod tests {
let mut bitv = 0 as uint;
b.iter(|| {
bitv |= (1 << ((r.next_u32() as uint) % uint::BITS));
&bitv
})
}

Expand All @@ -1571,6 +1572,7 @@ mod tests {
let mut bitv = SmallBitv::new(uint::BITS);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
&bitv
})
}

Expand All @@ -1580,6 +1582,7 @@ mod tests {
let mut bitv = BigBitv::new(~[0]);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
&bitv
})
}

Expand All @@ -1591,6 +1594,7 @@ mod tests {
let mut bitv = BigBitv::new(storage);
b.iter(|| {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
&bitv
})
}

Expand All @@ -1600,6 +1604,7 @@ mod tests {
let mut bitv = Bitv::new(BENCH_BITS, false);
b.iter(|| {
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
&bitv
})
}

Expand All @@ -1609,6 +1614,7 @@ mod tests {
let mut bitv = Bitv::new(uint::BITS, false);
b.iter(|| {
bitv.set((r.next_u32() as uint) % uint::BITS, true);
&bitv
})
}

Expand All @@ -1618,6 +1624,7 @@ mod tests {
let mut bitv = BitvSet::new();
b.iter(|| {
bitv.insert((r.next_u32() as uint) % uint::BITS);
&bitv
})
}

Expand All @@ -1627,6 +1634,7 @@ mod tests {
let mut bitv = BitvSet::new();
b.iter(|| {
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
&bitv
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ pub mod bench {
// measure
let mut i = 0;
bh.iter(|| {
map.find(&i);
let x = map.find(&i);
i = (i + 1) % n;
x
})
}
}
4 changes: 2 additions & 2 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,14 @@ mod test {
#[bench]
fn bench_buffered_reader(bh: &mut Harness) {
bh.iter(|| {
BufferedReader::new(NullStream);
BufferedReader::new(NullStream)
});
}

#[bench]
fn bench_buffered_writer(bh: &mut Harness) {
bh.iter(|| {
BufferedWriter::new(NullStream);
BufferedWriter::new(NullStream)
});
}

Expand Down
12 changes: 6 additions & 6 deletions src/libstd/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ mod bench {
let s = Struct { field: 10 };
let t = &s as &Trait;
bh.iter(|| {
t.method();
t.method()
});
}

#[bench]
fn trait_static_method_call(bh: &mut BenchHarness) {
let s = Struct { field: 10 };
bh.iter(|| {
s.method();
s.method()
});
}

Expand All @@ -310,21 +310,21 @@ mod bench {
fn match_option_some(bh: &mut BenchHarness) {
let x = Some(10);
bh.iter(|| {
let _q = match x {
match x {
Some(y) => y,
None => 11
};
}
});
}

#[bench]
fn match_vec_pattern(bh: &mut BenchHarness) {
let x = [1,2,3,4,5,6];
bh.iter(|| {
let _q = match x {
match x {
[1,2,3,..] => 10,
_ => 11
};
}
});
}
}
4 changes: 2 additions & 2 deletions src/libstd/rt/global_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ mod bench {
#[bench]
fn alloc_owned_small(bh: &mut BenchHarness) {
bh.iter(|| {
~10;
~10
})
}

#[bench]
fn alloc_owned_big(bh: &mut BenchHarness) {
bh.iter(|| {
~[10, ..1000];
~[10, ..1000]
})
}
}
6 changes: 3 additions & 3 deletions src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4356,7 +4356,7 @@ mod bench {

assert_eq!(100, s.len());
bh.iter(|| {
let _ = is_utf8(s);
is_utf8(s)
});
}

Expand All @@ -4365,7 +4365,7 @@ mod bench {
let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
assert_eq!(100, s.len());
bh.iter(|| {
let _ = is_utf8(s);
is_utf8(s)
});
}

Expand Down Expand Up @@ -4408,7 +4408,7 @@ mod bench {
#[bench]
fn bench_with_capacity(bh: &mut BenchHarness) {
bh.iter(|| {
let _ = with_capacity(100);
with_capacity(100)
});
}

Expand Down
19 changes: 11 additions & 8 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4385,22 +4385,23 @@ mod bench {
let mut vec: ~[uint] = ~[0u];
bh.iter(|| {
vec.push(0);
&vec
})
}

#[bench]
fn starts_with_same_vector(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i);
bh.iter(|| {
vec.starts_with(vec);
vec.starts_with(vec)
})
}

#[bench]
fn starts_with_single_element(bh: &mut BenchHarness) {
let vec: ~[uint] = ~[0u];
bh.iter(|| {
vec.starts_with(vec);
vec.starts_with(vec)
})
}

Expand All @@ -4410,23 +4411,23 @@ mod bench {
let mut match_vec: ~[uint] = vec::from_fn(99, |i| i);
match_vec.push(0);
bh.iter(|| {
vec.starts_with(match_vec);
vec.starts_with(match_vec)
})
}

#[bench]
fn ends_with_same_vector(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i);
bh.iter(|| {
vec.ends_with(vec);
vec.ends_with(vec)
})
}

#[bench]
fn ends_with_single_element(bh: &mut BenchHarness) {
let vec: ~[uint] = ~[0u];
bh.iter(|| {
vec.ends_with(vec);
vec.ends_with(vec)
})
}

Expand All @@ -4436,15 +4437,15 @@ mod bench {
let mut match_vec: ~[uint] = vec::from_fn(100, |i| i);
match_vec[0] = 200;
bh.iter(|| {
vec.starts_with(match_vec);
vec.starts_with(match_vec)
})
}

#[bench]
fn contains_last_element(bh: &mut BenchHarness) {
let vec: ~[uint] = vec::from_fn(100, |i| i);
bh.iter(|| {
vec.contains(&99u);
vec.contains(&99u)
})
}

Expand All @@ -4464,13 +4465,14 @@ mod bench {
ptr::set_memory(vp, 0, 1024);
v.set_len(1024);
}
v
});
}

#[bench]
fn zero_1kb_fixed_repeat(bh: &mut BenchHarness) {
bh.iter(|| {
let _v: ~[u8] = ~[0u8, ..1024];
~[0u8, ..1024]
});
}

Expand Down Expand Up @@ -4499,6 +4501,7 @@ mod bench {
for x in v.mut_iter() {
*x = 0;
}
v
});
}

Expand Down