Skip to content

Benchmark cleanup and additions #274

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 10 commits into from
52 changes: 28 additions & 24 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,11 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \
while-type-error.rs \
wrong-ret-type.rs \
), \
$(wildcard test/*fail/*.rs test/*fail/*.rc))

$(wildcard test/*fail/*.rs test/*fail/*.rc)) \
test/bench/shootout/fannkuchredux.rs \
test/bench/shootout/fasta.rs \
test/bench/shootout/binarytrees.rs \
$(wildcard test/bench/99-bottles/*rs)

ifdef MINGW_CROSS
TEST_XFAILS_BOOT += test/run-pass/native-mod.rc
Expand All @@ -585,8 +588,10 @@ TEST_XFAILS_BOOT += test/run-pass/native-mod.rc
TEST_XFAILS_RUSTC += test/run-pass/native-mod.rc
endif

BENCH_RS := $(wildcard test/bench/shootout/*rs) \
$(wildcard test/bench/99-bottles/*rs)
RPASS_RC := $(wildcard test/run-pass/*.rc)
RPASS_RS := $(wildcard test/run-pass/*.rs)
RPASS_RS := $(wildcard test/run-pass/*.rs) $(BENCH_RS)
RFAIL_RC := $(wildcard test/run-fail/*.rc)
RFAIL_RS := $(wildcard test/run-fail/*.rs)
CFAIL_RC := $(wildcard test/compile-fail/*.rc)
Expand Down Expand Up @@ -730,6 +735,18 @@ test/run-pass/%.out.tmp: test/run-pass/%$(CFG_EXE_SUFFIX) $(CFG_RUNTIME)
@$(call CFG_ECHO, run: $<)
$(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@

test/bench/shootout/%.out.tmp: test/bench/shootout/%$(CFG_EXE_SUFFIX) \
$(CFG_RUNTIME)
$(CFG_QUIET)rm -f $<.tmp
@$(call CFG_ECHO, run: $<)
$(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@

test/bench/99-bottles/%.out.tmp: test/bench/99-bottles/%$(CFG_EXE_SUFFIX) \
$(CFG_RUNTIME)
$(CFG_QUIET)rm -f $<.tmp
@$(call CFG_ECHO, run: $<)
$(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@

test/run-fail/%.out.tmp: test/run-fail/%$(CFG_EXE_SUFFIX) \
$(CFG_RUNTIME)
$(CFG_QUIET)rm -f $<.tmp
Expand Down Expand Up @@ -758,14 +775,13 @@ test/compile-fail/%.rustc.out.tmp: test/compile-fail/%.rs $(SREQ)
$(CFG_QUIET)grep --text --quiet \
"$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@

test/run-pass/%.boot$(CFG_EXE_SUFFIX): test/run-pass/%.rc $(BREQ)
@$(call CFG_ECHO, compile [boot]: $<)
$(BOOT) -o $@ $<
%.bc: %.rc $(SREQ)
@$(call CFG_ECHO, compile [rustc]: $<)
$(RUSTC) -o $@ $<

test/bench/shootout/%.boot$(CFG_EXE_SUFFIX): \
test/bench/shootout/%.rs $(BREQ)
@$(call CFG_ECHO, compile [boot]: $<)
$(BOOT) -o $@ $<
%.bc: %.rs $(SREQ)
@$(call CFG_ECHO, compile [rustc]: $<)
$(RUSTC) -o $@ $<

%.ll: %.bc
@$(call CFG_ECHO, dis [llvm]: $<)
Expand All @@ -788,26 +804,14 @@ test/bench/shootout/%.boot$(CFG_EXE_SUFFIX): \
@# programs, I\'ll live with the noise.
-$(CFG_QUIET)$(DSYMUTIL) $@

test/run-pass/%.bc: test/run-pass/%.rc $(SREQ)
@$(call CFG_ECHO, compile [rustc]: $<)
$(RUSTC) -o $@ $<

test/run-pass/%.boot$(CFG_EXE_SUFFIX): test/run-pass/%.rs $(BREQ)
%.boot$(CFG_EXE_SUFFIX): %.rs $(BREQ)
@$(call CFG_ECHO, compile [boot]: $<)
$(BOOT) -o $@ $<

test/run-pass/%.bc: test/run-pass/%.rs $(SREQ)
@$(call CFG_ECHO, compile [rustc]: $<)
$(RUSTC) -o $@ $<

test/run-fail/%.boot$(CFG_EXE_SUFFIX): test/run-fail/%.rs $(BREQ)
%.boot$(CFG_EXE_SUFFIX): %.rc $(BREQ)
@$(call CFG_ECHO, compile [boot]: $<)
$(BOOT) -o $@ $<

test/run-fail/%.bc: test/run-fail/%.rs $(SREQ)
@$(call CFG_ECHO, compile [rustc]: $<)
$(RUSTC) -o $@ $<


######################################################################
# Auto-dependency
Expand Down
1 change: 1 addition & 0 deletions src/README
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ test/ Testsuite (for both bootstrap and self-hosted)
test/compile-fail - Tests that should fail to compile
test/run-fail - Tests that should compile, run and fail
test/run-pass - Tests that should compile, run and succeed
test/bench - Benchmarks and miscellanea

Please be gentle, it's a work in progress.
17 changes: 17 additions & 0 deletions src/lib/_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ fn to_str(mutable int n, uint radix) -> str
}
}

fn pow(int base, uint exponent) -> int {

if (exponent == 0u) {
ret 1;
} else if (base == 0) {
ret 0;
} else {
auto accum = base;
auto count = exponent;
while (count > 1u) {
accum *= base;
count -= 1u;
}
ret accum;
}
}

// Local Variables:
// mode: rust;
// fill-column: 78;
Expand Down
20 changes: 0 additions & 20 deletions src/test/bench/99-bottles/Makefile

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/bench/99-bottles/r.sh

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/bench/shootout/binary-trees.rs

This file was deleted.

74 changes: 74 additions & 0 deletions src/test/bench/shootout/binarytrees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use std;

import std._int;

tag tree {
nil;
node(@tree, @tree, int);
}

fn item_check(@tree t) -> int {
alt (*t) {
case (nil) {
ret 0;
}
case (node(?left, ?right, ?item)) {
ret item + item_check(left) - item_check(right);
}
}
}

fn bottom_up_tree(int item, int depth) -> @tree{
if (depth > 0) {
ret @node(bottom_up_tree(2 * item - 1, depth - 1),
bottom_up_tree(2 * item, depth - 1),
item);
} else {
ret @nil;
}
}

fn main() {

auto n = 8;
auto min_depth = 4;
auto max_depth;
if (min_depth + 2 > n) {
max_depth = min_depth + 2;
} else {
max_depth = n;
}

auto stretch_depth = max_depth + 1;

auto stretch_tree = bottom_up_tree(0, stretch_depth);
log #fmt("stretch tree of depth %d\t check: %d",
stretch_depth, item_check(stretch_tree));

auto long_lived_tree = bottom_up_tree(0, max_depth);

auto depth = min_depth;
while (depth <= max_depth) {
auto iterations = _int.pow(2, (max_depth - depth + min_depth) as uint);
auto chk = 0;

auto i = 1;
while (i <= iterations) {
auto temp_tree = bottom_up_tree(i, depth);
chk += item_check(temp_tree);

temp_tree = bottom_up_tree(-i, depth);
chk += item_check(temp_tree);

i += 1;
}

log #fmt("%d\t trees of depth %d\t check: %d",
iterations * 2, depth, chk);

depth += 2;
}

log #fmt("long lived trees of depth %d\t check: %d",
max_depth, item_check(long_lived_tree));
}
99 changes: 99 additions & 0 deletions src/test/bench/shootout/fannkuchredux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Based on Isaac Gouy's fannkuchredux.csharp

use std;

import std._int;
import std._vec;

impure fn fannkuch(int n) -> int {

fn perm1init(uint i) -> mutable int {
ret i as int;
}
auto perm1init_ = perm1init; // Rustboot workaround

auto perm = _vec.init_elt[mutable int](0, n as uint);
auto perm1 = _vec.init_fn[mutable int](perm1init_, n as uint);
auto count = _vec.init_elt[mutable int](0, n as uint);

auto f = 0;
auto i = 0;
auto k = 0;
auto r = 0;
auto flips = 0;
auto nperm = 0;
auto checksum = 0;

r = n;
while (r > 0) {
i = 0;

while (r != 1) {
count.(r - 1) = r;
r -=1;
}

while (i < n) {
perm.(i) = perm1.(i);
i += 1;
}

// Count flips and update max and checksum
f = 0;
k = perm.(0);
while (k != 0) {
i = 0;
while (2 * i < k) {
auto t = perm.(i);
perm.(i) = perm.(k - i);
perm.(k - i) = t;
i += 1;
}
k = perm.(0);
f += 1;
}

if (f > flips) {
flips = f;
}

if ((nperm & 0x1) == 0) {
checksum += f;
} else {
checksum -= f;
}

// Use incremental change to generate another permutation
auto go = true;
while (go) {
if (r == n) {
log checksum;
ret flips;
}
auto p0 = perm1.(0);
i = 0;
while (i < r) {
auto j = i + 1;
perm1.(i) = perm1.(j);
i = j;
}
perm1.(r) = p0;

count.(r) -= 1;
if (count.(r) > 0) {
go = false;
} else {
r += 1;
}
}

nperm += 1;
}

ret flips;
}

impure fn main(vec[str] args) {
auto n = 7;
log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n));
}
11 changes: 11 additions & 0 deletions src/test/run-pass/lib-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ fn test_to_str() {
check (eq(_int.to_str(100, 10u), "100"));
}

fn test_pow() {
check (_int.pow(0, 0u) == 1);
check (_int.pow(0, 1u) == 0);
check (_int.pow(0, 2u) == 0);
check (_int.pow(-1, 0u) == -1);
check (_int.pow(1, 0u) == 1);
check (_int.pow(-3, 2u) == 9);
check (_int.pow(-3, 3u) == -27);
check (_int.pow(4, 9u) == 262144);
}

fn main() {
test_to_str();
}