Skip to content

Commit c6515ee

Browse files
committed
auto merge of #7193 : Thiez/rust/fixbench, r=cmr
This PR fixes a few problems with the benchmark, mentioned in #2913. Since I do not have a 4GB RAM machine (I run rust on a puny 2GB RAM VM) I can't test binarytrees with N=20. If it works we can close #2913. Fixes: 1) binarytrees prints "long lived trees of depth" instead of "long lived tree of depth" Fixes: 2) chameneosredux -- the whitespace printed by show_number should be the same as printed by show_color Already fixed: 3) spectralnorm prints an extra Fixes: 4) threadring prints an extra Fixes: 5) fasta -- strangely, output stops half-way through line 169 -- with another 8166 lines still to do. Could not test: 6) the latest binarytrees fails with input N=20 on a 4GB machine. r?
2 parents dfb7de8 + 7ba1a23 commit c6515ee

File tree

5 files changed

+62
-56
lines changed

5 files changed

+62
-56
lines changed

src/libextra/arena.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -39,7 +39,7 @@ use core::prelude::*;
3939
use list::{MutList, MutCons, MutNil};
4040

4141
use core::at_vec;
42-
use core::cast::{transmute, transmute_mut_region};
42+
use core::cast::{transmute, transmute_mut, transmute_mut_region};
4343
use core::cast;
4444
use core::libc::size_t;
4545
use core::ptr;
@@ -74,6 +74,7 @@ struct Chunk {
7474
is_pod: bool,
7575
}
7676

77+
#[mutable]
7778
pub struct Arena {
7879
// The head is separated out from the list as a unbenchmarked
7980
// microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
269270

270271
// The external interface
271272
#[inline]
272-
pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
273+
pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
273274
unsafe {
274275
// XXX: Borrow check
275-
let this = transmute_mut_region(self);
276-
if !intrinsics::needs_drop::<T>() {
277-
return this.alloc_pod(op);
276+
let this = transmute_mut(self);
277+
if intrinsics::needs_drop::<T>() {
278+
this.alloc_nonpod(op)
279+
} else {
280+
this.alloc_pod(op)
278281
}
279-
// XXX: Borrow check
280-
let this = transmute_mut_region(self);
281-
this.alloc_nonpod(op)
282282
}
283283
}
284284
}
285285

286286
#[test]
287287
fn test_arena_destructors() {
288-
let mut arena = Arena();
288+
let arena = Arena();
289289
for uint::range(0, 10) |i| {
290290
// Arena allocate something with drop glue to make sure it
291291
// doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
300300
#[should_fail]
301301
#[ignore(cfg(windows))]
302302
fn test_arena_destructors_fail() {
303-
let mut arena = Arena();
303+
let arena = Arena();
304304
// Put some stuff in the arena.
305305
for uint::range(0, 10) |i| {
306306
// Arena allocate something with drop glue to make sure it
+23-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// xfail-test
2-
3-
// Broken due to arena API problems.
4-
5-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
62
// file at the top-level directory of this distribution and at
73
// http://rust-lang.org/COPYRIGHT.
84
//
@@ -15,33 +11,35 @@
1511
extern mod extra;
1612
use extra::arena;
1713

18-
enum tree<'self> {
19-
nil,
20-
node(&'self tree<'self>, &'self tree<'self>, int),
14+
enum Tree<'self> {
15+
Nil,
16+
Node(&'self Tree<'self>, &'self Tree<'self>, int),
2117
}
2218

23-
fn item_check(t: &tree) -> int {
19+
fn item_check(t: &Tree) -> int {
2420
match *t {
25-
nil => { return 0; }
26-
node(left, right, item) => {
21+
Nil => { return 0; }
22+
Node(left, right, item) => {
2723
return item + item_check(left) - item_check(right);
2824
}
2925
}
3026
}
3127

32-
fn bottom_up_tree<'r>(arena: &'r mut arena::Arena, item: int, depth: int)
33-
-> &'r tree<'r> {
28+
fn bottom_up_tree<'r>(arena: &'r arena::Arena, item: int, depth: int)
29+
-> &'r Tree<'r> {
3430
if depth > 0 {
3531
return arena.alloc(
36-
|| node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
32+
|| Node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
3733
bottom_up_tree(arena, 2 * item, depth - 1),
3834
item));
3935
}
40-
return arena.alloc(|| nil);
36+
return arena.alloc(|| Nil);
4137
}
4238

4339
fn main() {
44-
let args = os::args();
40+
use std::os;
41+
use std::int;
42+
let args = std::os::args();
4543
let args = if os::getenv(~"RUST_BENCH").is_some() {
4644
~[~"", ~"17"]
4745
} else if args.len() <= 1u {
@@ -59,34 +57,34 @@ fn main() {
5957
max_depth = n;
6058
}
6159

62-
let mut stretch_arena = arena::Arena();
60+
let stretch_arena = arena::Arena();
6361
let stretch_depth = max_depth + 1;
64-
let stretch_tree = bottom_up_tree(&mut stretch_arena, 0, stretch_depth);
62+
let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
6563

66-
io::println(fmt!("stretch tree of depth %d\t check: %d",
64+
println(fmt!("stretch tree of depth %d\t check: %d",
6765
stretch_depth,
6866
item_check(stretch_tree)));
6967

70-
let mut long_lived_arena = arena::Arena();
71-
let long_lived_tree = bottom_up_tree(&mut long_lived_arena, 0, max_depth);
68+
let long_lived_arena = arena::Arena();
69+
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
7270
let mut depth = min_depth;
7371
while depth <= max_depth {
7472
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
7573
let mut chk = 0;
7674
let mut i = 1;
7775
while i <= iterations {
78-
let mut temp_tree = bottom_up_tree(&mut long_lived_arena, i, depth);
76+
let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
7977
chk += item_check(temp_tree);
80-
temp_tree = bottom_up_tree(&mut long_lived_arena, -i, depth);
78+
temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
8179
chk += item_check(temp_tree);
8280
i += 1;
8381
}
84-
io::println(fmt!("%d\t trees of depth %d\t check: %d",
82+
println(fmt!("%d\t trees of depth %d\t check: %d",
8583
iterations * 2, depth,
8684
chk));
8785
depth += 2;
8886
}
89-
io::println(fmt!("long lived trees of depth %d\t check: %d",
87+
println(fmt!("long lived tree of depth %d\t check: %d",
9088
max_depth,
9189
item_check(long_lived_tree)));
9290
}

src/test/bench/shootout-chameneos-redux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn show_number(nn: uint) -> ~str {
8585
out = show_digit(dig) + " " + out;
8686
}
8787

88-
return out;
88+
return ~" " + out;
8989
}
9090
9191
fn transform(aa: color, bb: color) -> color {

src/test/bench/shootout-fasta.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -19,16 +19,14 @@ extern mod extra;
1919

2020
use std::int;
2121
use std::io;
22-
use std::option;
2322
use std::os;
2423
use std::rand::Rng;
2524
use std::rand;
2625
use std::result;
2726
use std::str;
2827
use std::uint;
29-
use std::vec;
3028

31-
fn LINE_LENGTH() -> uint { return 60u; }
29+
static LINE_LENGTH: uint = 60u;
3230

3331
struct MyRandom {
3432
last: u32
@@ -81,7 +79,7 @@ fn make_random_fasta(wr: @io::Writer,
8179
for uint::range(0u, n as uint) |_i| {
8280
op.push_char(select_random(myrandom_next(rng, 100u32),
8381
copy genelist));
84-
if op.len() >= LINE_LENGTH() {
82+
if op.len() >= LINE_LENGTH {
8583
wr.write_line(op);
8684
op = ~"";
8785
}
@@ -90,18 +88,18 @@ fn make_random_fasta(wr: @io::Writer,
9088
}
9189

9290
fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
93-
unsafe {
94-
wr.write_line(~">" + id + " " + desc);
95-
let mut op: ~str = ~"";
96-
let sl: uint = s.len();
97-
for uint::range(0u, n as uint) |i| {
98-
str::raw::push_byte(&mut op, s[i % sl]);
99-
if op.len() >= LINE_LENGTH() {
100-
wr.write_line(op);
101-
op = ~"";
102-
}
91+
wr.write_line(~">" + id + " " + desc);
92+
let mut op = str::with_capacity( LINE_LENGTH );
93+
let sl = s.len();
94+
for uint::range(0u, n as uint) |i| {
95+
if (op.len() >= LINE_LENGTH) {
96+
wr.write_line( op );
97+
op = str::with_capacity( LINE_LENGTH );
10398
}
104-
if op.len() > 0u { wr.write_line(op); }
99+
op.push_char( s[i % sl] as char );
100+
}
101+
if op.len() > 0 {
102+
wr.write_line(op)
105103
}
106104
}
107105
@@ -111,7 +109,7 @@ fn acid(ch: char, prob: u32) -> AminoAcids {
111109
112110
fn main() {
113111
let args = os::args();
114-
let args = if os::getenv(~"RUST_BENCH").is_some() {
112+
let args = if os::getenv("RUST_BENCH").is_some() {
115113
// alioth tests k-nucleotide with this data at 25,000,000
116114
~[~"", ~"5000000"]
117115
} else if args.len() <= 1u {
@@ -120,9 +118,9 @@ fn main() {
120118
args
121119
};
122120

123-
let writer = if os::getenv(~"RUST_BENCH").is_some() {
121+
let writer = if os::getenv("RUST_BENCH").is_some() {
124122
result::get(&io::file_writer(&Path("./shootout-fasta.data"),
125-
~[io::Truncate, io::Create]))
123+
[io::Truncate, io::Create]))
126124
} else {
127125
io::stdout()
128126
};

src/test/bench/shootout-spectralnorm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use std::f64;
212
use std::from_str::FromStr;
313
use std::os;

0 commit comments

Comments
 (0)