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

Commit 39120d7

Browse files
authored
Merge pull request #17 from nnethercote/compare-script
Add a script to compare two compilers.
2 parents 744f6f3 + 7afc56b commit 39120d7

File tree

18 files changed

+169
-49
lines changed

18 files changed

+169
-49
lines changed

README.md

+16-7
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

+76
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

+1-1
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

+5-3
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

+5-3
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

+5-3
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

+5-3
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
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
+5-3
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

+5-3
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

+5-3
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

+1-1
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

+5-3
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

+5-3
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/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version = "0.1.0"
44
authors = ["Niko Matsakis <[email protected]>"]
55

66
[dependencies]
7-
syntex = "0.42.2"
7+
syntex = "= 0.42.2"

syntex-0.42.2-incr-clean/makefile

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
all:
2-
RUSTFLAGS="-Z incremental=incr -Z incremental-info" $(CARGO_BUILD)
1+
.PHONY: all touch clean
32

4-
touch:
5-
cargo clean # note: leave the `incr` directory alone
3+
# The way that this is intended to work is as follows:
4+
# - We force the incremental data to be stored in the `incr` directory
5+
# - We clean precisely the syntex_syntax crate; but we do not touch the `incr` directory
6+
# - We rebuild, which will reuse the results from `incr` directory
7+
#
8+
# This can be compared against `syntex-0.42.2`, which does the same
9+
# thing, but without the `incr` directory.
610

11+
all:
12+
RUSTFLAGS="-Z incremental=incr" \
13+
cargo rustc -p syntex_syntax -- $(CARGO_RUSTC_OPTS) -Z incremental-info
14+
touch:
15+
cargo clean -p syntex_syntax
716
clean:
817
rm -rf incr/*
918
cargo clean
19+

syntex-0.42.2/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version = "0.1.0"
44
authors = ["Niko Matsakis <[email protected]>"]
55

66
[dependencies]
7-
syntex = "0.42.2"
7+
syntex = "= 0.42.2"

syntex-0.42.2/makefile

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
.PHONY: all touch clean
2+
3+
# Time how long it takes to build `syntex_syntax`. See
4+
# `../syntax-0.42.2-incr-clean/makefile` for some further notes.
5+
16
all:
2-
$(CARGO_BUILD)
7+
cargo rustc -p syntex_syntax -- $(CARGO_RUSTC_OPTS)
38
touch:
4-
rm -rf target/debug/*
9+
cargo clean -p syntex_syntax
510
clean:
6-
rm target -rf
7-
rm Cargo.lock
11+
cargo clean
12+

0 commit comments

Comments
 (0)