Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit 853db5f

Browse files
committed
Add a script to compare two compilers.
This commit adds a new script, `compare.py`, that can be used to compared the speed of two compilers. Example output: ``` futures-rs-test 4.689s vs 4.668s --> 1.004x faster (variance: 1.001x, 1.008x) helloworld 0.232s vs 0.230s --> 1.007x faster (variance: 1.009x, 1.012x) html5ever-2016- 7.670s vs 7.669s --> 1.000x faster (variance: 1.008x, 1.009x) hyper.0.5.0 5.304s vs 5.308s --> 0.999x faster (variance: 1.007x, 1.005x) inflate-0.1.0 4.849s vs 4.884s --> 0.993x faster (variance: 1.019x, 1.009x) issue-32062-equ 0.400s vs 0.396s --> 1.009x faster (variance: 1.014x, 1.021x) issue-32278-big 1.872s vs 1.833s --> 1.022x faster (variance: 1.021x, 1.018x) jld-day15-parse 1.903s vs 1.875s --> 1.015x faster (variance: 1.006x, 1.002x) piston-image-0. 12.910s vs 12.932s --> 0.998x faster (variance: 1.010x, 1.006x) regex.0.1.30 2.622s vs 2.629s --> 0.997x faster (variance: 1.020x, 1.018x) rust-encoding-0 3.269s vs 3.245s --> 1.007x faster (variance: 1.022x, 1.022x) syntex-0.42.2 0.240s vs 0.242s --> 0.992x faster (variance: 1.011x, 1.004x) syntex-0.42.2-i 48.252s vs 48.070s --> 1.004x faster (variance: 1.011x, 1.006x) ``` In support of this, the commit also does the following. - Clarifies the meaning of the `touch` target. It now touches or removes files in such a way that subsequent `make` invocations will rebuild just the crate of interest for each benchmark. Most of the `touch` targets required changing to achieve this. - Replaces use of the CARGO_BUILD environment variable with CARGO_RUSTC_OPTS. This means that all makefiles are now more uniform -- they now all invoke `cargo rust` directly, and none of them specify `-Ztime-passes -Zinput-stats`. The commit also updates appropriately `process.sh` for this change. - Uses `cargo clean` more extensively in makefile `clean` targets. - Adds `.PHONY` declarations to all makefiles missing them. It can't hurt. - Rewrites `README.md` to reflect all the above changes, and to remove outdated and incorrect information.
1 parent 744f6f3 commit 853db5f

File tree

16 files changed

+153
-45
lines changed

16 files changed

+153
-45
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
# Benchmarks for Rust compiler performance
22

3-
Recorded timings shown at: http://perf.rust-lang.org/
3+
Each subdirectory contains a single benchmark. Although benchmarks may contain
4+
multiple crates, each benchmark has one "crate of interest" which is the one
5+
whose compilation time is measured.
46

5-
Each subdirectory should contain a single crate for benchmarking. It should
6-
include a makefile so that the crate can be built by running `make`. Any use of
7-
rustc should include the argument `-Ztime-passes`. See for example the
8-
helloworld crate. Each makefile should build only one crate.
7+
Each benchmark has a makefile with the following targets.
8+
* `all`: builds the entire benchmark. The `CARGO_RUSTC_OPTS` environment
9+
variable can be specified to pass extra arguments to rustc invocations.
10+
* `touch`: touches or removes files in such a way that a subsequent `make`
11+
invocation will build only the crate of interest.
12+
* `clean`: removes all build artifacts.
13+
14+
A historical record of timings is shown at: http://perf.rust-lang.org/. This
15+
site makes use of the `process.sh` script plus some auxiliary scripts not in
16+
this repository.
17+
18+
Local runs comparing two different compilers can be performed with
19+
`compare.py`. This is useful when evaluating compile-time optimizations.
920

10-
regex is duplicated because there are two crates, and the current scipt only
11-
handles one crate per directory. It would be better to have a manifest or something.

compare.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#! /usr/bin/python
2+
#
3+
# Compares the speed of two different compilers on one or more benchmarks in
4+
# the suite.
5+
6+
from __future__ import division, print_function
7+
8+
import os
9+
import subprocess
10+
import sys
11+
import time
12+
13+
def run_test(dir, rustc):
14+
os.chdir(dir)
15+
16+
# First clean and rebuild from scratch. This downloads any necessary code
17+
# and builds preliminary crates.
18+
#
19+
# We use call() instead of check_call() for `make clean` because it can
20+
# fail reasonably, e.g. if we try to delete a Cargo.lock file thta isn't
21+
# present.
22+
subprocess.call('make clean > /dev/null 2>&1', shell=True)
23+
make_env = os.environ.copy()
24+
make_env['RUSTC'] = rustc
25+
subprocess.check_call('make > /dev/null 2>&1', env=make_env, shell=True)
26+
27+
# Measure compilation speed of the crate of interest three times.
28+
times = []
29+
for i in range(0, 3):
30+
subprocess.check_call('make touch > /dev/null 2>&1', shell=True)
31+
t1 = time.time()
32+
subprocess.check_call('make > /dev/null 2>&1', env=make_env, shell=True)
33+
t2 = time.time()
34+
t = t2 - t1
35+
times.append(t)
36+
37+
os.chdir('..')
38+
39+
return times
40+
41+
42+
if __name__ == '__main__':
43+
if (len(sys.argv)) < 3:
44+
print('usage:', sys.argv[0], '<rustc1>', '<rustc2>', '[benchmarks]')
45+
sys.exit(1)
46+
47+
rustc1 = sys.argv[1]
48+
rustc2 = sys.argv[2]
49+
50+
# Get all the directories, excluding ".git".
51+
all_dirs = [f for f in os.listdir('.') if os.path.isdir(f) and f != ".git"]
52+
53+
# Get any specified directories. Otherwise, default to all of them.
54+
dirs = sys.argv[3:]
55+
if dirs:
56+
for dir in dirs:
57+
if dir not in all_dirs:
58+
print('error: bad directory specified: \'' + dir + '\'')
59+
sys.exit(1)
60+
else:
61+
dirs = all_dirs
62+
63+
# Run the requested benchmarks.
64+
for dir in dirs:
65+
times1 = run_test(dir, rustc1)
66+
times2 = run_test(dir, rustc2)
67+
68+
min1 = min(times1)
69+
min2 = min(times2)
70+
max1 = max(times1)
71+
max2 = max(times2)
72+
73+
print('{:15s} {:6.3f}s vs {:6.3f}s --> '
74+
'{:5.3f}x faster (variance: {:5.3f}x, {:5.3f}x)'.
75+
format(dir[:15], min1, min2, min1 / min2, max1 / min1, max2 / min2))
76+

futures-rs-test-all/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: all touch clean
22

33
all:
4-
cargo rustc --test all --verbose -- -Ztime-passes -Zinput-stats
4+
cargo rustc --test all -- $(CARGO_RUSTC_OPTS)
55
touch:
66
rm -f target/debug/all-*
77
clean:

helloworld/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

html5ever-2016-08-25/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

hyper.0.5.0/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

inflate-0.1.0/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

jld-day15-parser/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

piston-image-0.10.3/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

process.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TIMES_DIR=/home/ncameron/times
44
SCRIPTS_DIR=/home/ncameron/times-scripts
55

66
START=$(pwd)
7-
export CARGO_BUILD="cargo rustc -- -Ztime-passes -Zinput-stats"
7+
export CARGO_RUSTC_OPTS="-Ztime-passes -Zinput-stats"
88
export PATH=$RUSTC_DIR/bin:$PATH
99

1010
for dir in *; do

regex.0.1.30/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

rust-encoding-0.3.0/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

syntex-0.42.2-incr-clean/makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
all:
2-
RUSTFLAGS="-Z incremental=incr -Z incremental-info" $(CARGO_BUILD)
1+
.PHONY: all touch clean
32

3+
all:
4+
RUSTFLAGS="-Z incremental=incr -Z incremental-info" cargo rustc -- $(CARGO_RUSTC_OPTS)
45
touch:
56
cargo clean # note: leave the `incr` directory alone
6-
77
clean:
88
rm -rf incr/*
99
cargo clean
10+
rm Cargo.lock

syntex-0.42.2/makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.PHONY: all touch clean
2+
13
all:
2-
$(CARGO_BUILD)
4+
cargo rustc -- $(CARGO_RUSTC_OPTS)
35
touch:
4-
rm -rf target/debug/*
6+
find . -name '*.rs' | xargs touch
57
clean:
6-
rm target -rf
8+
cargo clean
79
rm Cargo.lock

0 commit comments

Comments
 (0)