Skip to content

Commit 4cf155b

Browse files
Add benchmark scripts (#287)
1 parent d45e921 commit 4cf155b

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

bin/benchmark-in-docker.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Synopsis:
4+
# Benchmark the test runner Docker image.
5+
# Each run will clean the test directory being used to prevent previous runs from affecting the results.
6+
7+
# Environment:
8+
# SKIP_DOCKER_BUILD: if set, skip building the Docker image
9+
10+
# Output:
11+
# Outputs performance metrics.
12+
13+
# Example:
14+
# ./bin/benchmark-in-docker.sh
15+
16+
set -eo pipefail
17+
18+
die() { echo "$*" >&2; exit 1; }
19+
20+
required_tool() {
21+
command -v "${1}" >/dev/null 2>&1 ||
22+
die "${1} is required but not installed. Please install it and make sure it's in your PATH."
23+
}
24+
25+
required_tool docker
26+
required_tool hyperfine
27+
28+
# Pre-build the Docker image
29+
if [ -z "${SKIP_DOCKER_BUILD}" ]; then
30+
docker build --rm -t exercism/csharp-test-runner .
31+
else
32+
echo "Skipping docker build because SKIP_DOCKER_BUILD is set."
33+
fi
34+
35+
hyperfine \
36+
--parameter-list slug $(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",") \
37+
--prepare 'git clean -xdfq tests/{slug}' \
38+
'SKIP_DOCKER_BUILD=true bin/run-in-docker.sh {slug} tests/{slug} tests/{slug}'

bin/benchmark.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# Synopsis:
4+
# Benchmark the test runner code.
5+
# Each run will clean the test directory being used to prevent previous runs from affecting the results.
6+
7+
# Output:
8+
# Outputs performance metrics.
9+
10+
# Example:
11+
# ./bin/benchmark.sh
12+
13+
set -eo pipefail
14+
15+
die() { echo "$*" >&2; exit 1; }
16+
17+
required_tool() {
18+
command -v "${1}" >/dev/null 2>&1 ||
19+
die "${1} is required but not installed. Please install it and make sure it's in your PATH."
20+
}
21+
22+
required_tool hyperfine
23+
24+
hyperfine \
25+
--parameter-list slug $(find tests -maxdepth 1 -mindepth 1 -type d -printf $'%f\n' | paste -sd ",") \
26+
--prepare 'git clean -xdfq tests/{slug}' \
27+
'bin/run.sh {slug} tests/{slug} tests/{slug}'

0 commit comments

Comments
 (0)