Skip to content

Improvement of shootout-binarytrees.rs #20887

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

Merged
merged 1 commit into from
Jan 11, 2015

Conversation

TeXitoi
Copy link
Contributor

@TeXitoi TeXitoi commented Jan 10, 2015

Part of #18085

Instead of using an Enum, we use a struct with Option<&Tree> as leaves. It allow
to limit a lot of allocation.

before:

texitoi@vaio:~/dev/benchmarksgame-rs$ time ./bin/binary-trees-orig 20
stretch tree of depth 21     check: -1
2097152  trees of depth 4    check: -2097152
524288   trees of depth 6    check: -524288
131072   trees of depth 8    check: -131072
32768    trees of depth 10   check: -32768
8192     trees of depth 12   check: -8192
2048     trees of depth 14   check: -2048
512  trees of depth 16   check: -512
128  trees of depth 18   check: -128
32   trees of depth 20   check: -32
long lived tree of depth 20  check: -1

real    0m3.860s
user    0m11.032s
sys 0m3.572s

after:

texitoi@vaio:~/dev/benchmarksgame-rs$ time ./bin/binary-trees 20
stretch tree of depth 21     check: -1
2097152  trees of depth 4    check: -2097152
524288   trees of depth 6    check: -524288
131072   trees of depth 8    check: -131072
32768    trees of depth 10   check: -32768
8192     trees of depth 12   check: -8192
2048     trees of depth 14   check: -2048
512  trees of depth 16   check: -512
128  trees of depth 18   check: -128
32   trees of depth 20   check: -32
long lived tree of depth 20  check: -1

real    0m2.824s
user    0m9.224s
sys 0m1.428s

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

Part of rust-lang#18085

Instead of using an Enum, we use a struct with Option<&Tree> as leaves. It allow
to limit a lot of allocation.

before:
```
texitoi@vaio:~/dev/benchmarksgame-rs$ time ./bin/binary-trees-orig 20
stretch tree of depth 21	 check: -1
2097152	 trees of depth 4	 check: -2097152
524288	 trees of depth 6	 check: -524288
131072	 trees of depth 8	 check: -131072
32768	 trees of depth 10	 check: -32768
8192	 trees of depth 12	 check: -8192
2048	 trees of depth 14	 check: -2048
512	 trees of depth 16	 check: -512
128	 trees of depth 18	 check: -128
32	 trees of depth 20	 check: -32
long lived tree of depth 20	 check: -1

real	0m3.860s
user	0m11.032s
sys	0m3.572s
```
after:
```
texitoi@vaio:~/dev/benchmarksgame-rs$ time ./bin/binary-trees 20
stretch tree of depth 21	 check: -1
2097152	 trees of depth 4	 check: -2097152
524288	 trees of depth 6	 check: -524288
131072	 trees of depth 8	 check: -131072
32768	 trees of depth 10	 check: -32768
8192	 trees of depth 12	 check: -8192
2048	 trees of depth 14	 check: -2048
512	 trees of depth 16	 check: -512
128	 trees of depth 18	 check: -128
32	 trees of depth 20	 check: -32
long lived tree of depth 20	 check: -1

real	0m2.824s
user	0m9.224s
sys	0m1.428s
```
@kud1ing
Copy link

kud1ing commented Jan 10, 2015

Nice. By the way, have you noticed the build errors?http://benchmarksgame.alioth.debian.org/u64q/program.php?test=binarytrees&lang=rust&id=1

@TeXitoi
Copy link
Contributor Author

TeXitoi commented Jan 10, 2015

bors added a commit that referenced this pull request Jan 10, 2015
Improvement of shootout-binarytrees.rs

Reviewed-by: alexcrichton
@bors bors merged commit 629bcdd into rust-lang:master Jan 11, 2015
@brson
Copy link
Contributor

brson commented Jan 12, 2015

Sweet wins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants