Skip to content

Commit 665555d

Browse files
lpyalexcrichton
authored andcommitted
return value/use extra::test::black_box in benchmarks
1 parent 18477ac commit 665555d

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

src/libcollections/bitv.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,7 @@ mod tests {
15611561
let mut bitv = 0 as uint;
15621562
b.iter(|| {
15631563
bitv |= (1 << ((r.next_u32() as uint) % uint::BITS));
1564+
&bitv
15641565
})
15651566
}
15661567

@@ -1570,6 +1571,7 @@ mod tests {
15701571
let mut bitv = SmallBitv::new(uint::BITS);
15711572
b.iter(|| {
15721573
bitv.set((r.next_u32() as uint) % uint::BITS, true);
1574+
&bitv
15731575
})
15741576
}
15751577

@@ -1579,6 +1581,7 @@ mod tests {
15791581
let mut bitv = BigBitv::new(~[0]);
15801582
b.iter(|| {
15811583
bitv.set((r.next_u32() as uint) % uint::BITS, true);
1584+
&bitv
15821585
})
15831586
}
15841587

@@ -1590,6 +1593,7 @@ mod tests {
15901593
let mut bitv = BigBitv::new(storage);
15911594
b.iter(|| {
15921595
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
1596+
&bitv
15931597
})
15941598
}
15951599

@@ -1599,6 +1603,7 @@ mod tests {
15991603
let mut bitv = Bitv::new(BENCH_BITS, false);
16001604
b.iter(|| {
16011605
bitv.set((r.next_u32() as uint) % BENCH_BITS, true);
1606+
&bitv
16021607
})
16031608
}
16041609

@@ -1608,6 +1613,7 @@ mod tests {
16081613
let mut bitv = Bitv::new(uint::BITS, false);
16091614
b.iter(|| {
16101615
bitv.set((r.next_u32() as uint) % uint::BITS, true);
1616+
&bitv
16111617
})
16121618
}
16131619

@@ -1617,6 +1623,7 @@ mod tests {
16171623
let mut bitv = BitvSet::new();
16181624
b.iter(|| {
16191625
bitv.insert((r.next_u32() as uint) % uint::BITS);
1626+
&bitv
16201627
})
16211628
}
16221629

@@ -1626,6 +1633,7 @@ mod tests {
16261633
let mut bitv = BitvSet::new();
16271634
b.iter(|| {
16281635
bitv.insert((r.next_u32() as uint) % BENCH_BITS);
1636+
&bitv
16291637
})
16301638
}
16311639

src/libcollections/deque.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ pub mod bench {
115115
// measure
116116
let mut i = 0;
117117
bh.iter(|| {
118-
map.find(&i);
118+
let x = map.find(&i);
119119
i = (i + 1) % n;
120+
x
120121
})
121122
}
122123
}

src/libstd/io/buffered.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,14 @@ mod test {
565565
#[bench]
566566
fn bench_buffered_reader(bh: &mut Harness) {
567567
bh.iter(|| {
568-
BufferedReader::new(NullStream);
568+
BufferedReader::new(NullStream)
569569
});
570570
}
571571

572572
#[bench]
573573
fn bench_buffered_writer(bh: &mut Harness) {
574574
bh.iter(|| {
575-
BufferedWriter::new(NullStream);
575+
BufferedWriter::new(NullStream)
576576
});
577577
}
578578

src/libstd/mem.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ mod bench {
292292
let s = Struct { field: 10 };
293293
let t = &s as &Trait;
294294
bh.iter(|| {
295-
t.method();
295+
t.method()
296296
});
297297
}
298298

299299
#[bench]
300300
fn trait_static_method_call(bh: &mut BenchHarness) {
301301
let s = Struct { field: 10 };
302302
bh.iter(|| {
303-
s.method();
303+
s.method()
304304
});
305305
}
306306

@@ -310,21 +310,21 @@ mod bench {
310310
fn match_option_some(bh: &mut BenchHarness) {
311311
let x = Some(10);
312312
bh.iter(|| {
313-
let _q = match x {
313+
match x {
314314
Some(y) => y,
315315
None => 11
316-
};
316+
}
317317
});
318318
}
319319

320320
#[bench]
321321
fn match_vec_pattern(bh: &mut BenchHarness) {
322322
let x = [1,2,3,4,5,6];
323323
bh.iter(|| {
324-
let _q = match x {
324+
match x {
325325
[1,2,3,..] => 10,
326326
_ => 11
327-
};
327+
}
328328
});
329329
}
330330
}

src/libstd/rt/global_heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ mod bench {
112112
#[bench]
113113
fn alloc_owned_small(bh: &mut BenchHarness) {
114114
bh.iter(|| {
115-
~10;
115+
~10
116116
})
117117
}
118118

119119
#[bench]
120120
fn alloc_owned_big(bh: &mut BenchHarness) {
121121
bh.iter(|| {
122-
~[10, ..1000];
122+
~[10, ..1000]
123123
})
124124
}
125125
}

src/libstd/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,7 +4357,7 @@ mod bench {
43574357
43584358
assert_eq!(100, s.len());
43594359
bh.iter(|| {
4360-
let _ = is_utf8(s);
4360+
is_utf8(s)
43614361
});
43624362
}
43634363
@@ -4366,7 +4366,7 @@ mod bench {
43664366
let s = bytes!("𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰");
43674367
assert_eq!(100, s.len());
43684368
bh.iter(|| {
4369-
let _ = is_utf8(s);
4369+
is_utf8(s)
43704370
});
43714371
}
43724372
@@ -4409,7 +4409,7 @@ mod bench {
44094409
#[bench]
44104410
fn bench_with_capacity(bh: &mut BenchHarness) {
44114411
bh.iter(|| {
4412-
let _ = with_capacity(100);
4412+
with_capacity(100)
44134413
});
44144414
}
44154415

src/libstd/vec.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,22 +4428,23 @@ mod bench {
44284428
let mut vec: ~[uint] = ~[0u];
44294429
bh.iter(|| {
44304430
vec.push(0);
4431+
&vec
44314432
})
44324433
}
44334434

44344435
#[bench]
44354436
fn starts_with_same_vector(bh: &mut BenchHarness) {
44364437
let vec: ~[uint] = vec::from_fn(100, |i| i);
44374438
bh.iter(|| {
4438-
vec.starts_with(vec);
4439+
vec.starts_with(vec)
44394440
})
44404441
}
44414442

44424443
#[bench]
44434444
fn starts_with_single_element(bh: &mut BenchHarness) {
44444445
let vec: ~[uint] = ~[0u];
44454446
bh.iter(|| {
4446-
vec.starts_with(vec);
4447+
vec.starts_with(vec)
44474448
})
44484449
}
44494450

@@ -4453,23 +4454,23 @@ mod bench {
44534454
let mut match_vec: ~[uint] = vec::from_fn(99, |i| i);
44544455
match_vec.push(0);
44554456
bh.iter(|| {
4456-
vec.starts_with(match_vec);
4457+
vec.starts_with(match_vec)
44574458
})
44584459
}
44594460

44604461
#[bench]
44614462
fn ends_with_same_vector(bh: &mut BenchHarness) {
44624463
let vec: ~[uint] = vec::from_fn(100, |i| i);
44634464
bh.iter(|| {
4464-
vec.ends_with(vec);
4465+
vec.ends_with(vec)
44654466
})
44664467
}
44674468

44684469
#[bench]
44694470
fn ends_with_single_element(bh: &mut BenchHarness) {
44704471
let vec: ~[uint] = ~[0u];
44714472
bh.iter(|| {
4472-
vec.ends_with(vec);
4473+
vec.ends_with(vec)
44734474
})
44744475
}
44754476

@@ -4479,15 +4480,15 @@ mod bench {
44794480
let mut match_vec: ~[uint] = vec::from_fn(100, |i| i);
44804481
match_vec[0] = 200;
44814482
bh.iter(|| {
4482-
vec.starts_with(match_vec);
4483+
vec.starts_with(match_vec)
44834484
})
44844485
}
44854486

44864487
#[bench]
44874488
fn contains_last_element(bh: &mut BenchHarness) {
44884489
let vec: ~[uint] = vec::from_fn(100, |i| i);
44894490
bh.iter(|| {
4490-
vec.contains(&99u);
4491+
vec.contains(&99u)
44914492
})
44924493
}
44934494

@@ -4507,13 +4508,14 @@ mod bench {
45074508
ptr::set_memory(vp, 0, 1024);
45084509
v.set_len(1024);
45094510
}
4511+
v
45104512
});
45114513
}
45124514

45134515
#[bench]
45144516
fn zero_1kb_fixed_repeat(bh: &mut BenchHarness) {
45154517
bh.iter(|| {
4516-
let _v: ~[u8] = ~[0u8, ..1024];
4518+
~[0u8, ..1024]
45174519
});
45184520
}
45194521

@@ -4542,6 +4544,7 @@ mod bench {
45424544
for x in v.mut_iter() {
45434545
*x = 0;
45444546
}
4547+
v
45454548
});
45464549
}
45474550

0 commit comments

Comments
 (0)