-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-bench.sh
executable file
·61 lines (53 loc) · 3.4 KB
/
run-bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -e
# Build stuff
echo 'Building release version'
cargo build --release
echo 'Building debug version (will be used as test input)'
cargo build
BENCH_FILE_MODE_FILE="_bench_file.md"
BENCH_DATA_MODE_FILE="_bench_data_file.md"
BENCH_UNICODE_FILE_MODE_FILE="_bench_file_unicode.md"
# Run benchmarks
hyperfine -w 5 'target/release/strings target/debug/strings' 'strings target/debug/strings' --export-markdown $BENCH_FILE_MODE_FILE
hyperfine -w 5 'target/release/strings -d target/debug/strings' 'strings -d target/debug/strings' --export-markdown $BENCH_DATA_MODE_FILE
# strings crashes on big (target/debug/strings) file, so using a smaller file.
# Don't trust the result a lot.
hyperfine -w 5 'target/release/strings -u escape target/release/strings' 'strings -Ue target/release/strings' --export-markdown $BENCH_UNICODE_FILE_MODE_FILE
TIME_RUN_COMMAND="$(which time) --verbose"
EXTRACT_STATS_COMMAND="sed -n -e 10p -e 14p -e 15p"
TIME_OUTPUT_RUST_FILE_MODE=$(${TIME_RUN_COMMAND} target/release/strings target/debug/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
TIME_OUTPUT_GDB_FILE_MODE=$(${TIME_RUN_COMMAND} strings target/debug/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
TIME_OUTPUT_RUST_DATA_MODE=$(${TIME_RUN_COMMAND} target/release/strings -d target/debug/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
TIME_OUTPUT_GDB_DATA_MODE=$(${TIME_RUN_COMMAND} strings -d target/debug/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
TIME_OUTPUT_RUST_UNICODE_FILE_MODE=$(${TIME_RUN_COMMAND} target/release/strings -u escape target/release/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
TIME_OUTPUT_GDB_UNICODE_FILE_MODE=$(${TIME_RUN_COMMAND} strings -Ue target/release/strings 2>&1 >/dev/null | ${EXTRACT_STATS_COMMAND})
# Generate README
echo -en '## Performance comparison\n\n' > benchmarks.md
echo -en '`strings` version ' >> benchmarks.md
strings --version | grep -P -o -e "(\d\.\d.*)" >> benchmarks.md
echo -en '\n' >> benchmarks.md
echo -en '### ASCII chars search, complete file scan (file stream mode)\n\n' >> benchmarks.md
cat $BENCH_FILE_MODE_FILE >> benchmarks.md
rm $BENCH_FILE_MODE_FILE
echo -en '\n' >> benchmarks.md
echo -en '#### Rust variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_RUST_FILE_MODE}\n\n" >> benchmarks.md
echo -en '#### C variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_GDB_FILE_MODE}\n\n" >> benchmarks.md
echo -en '### ASCII chars search, only data section(s) scan (in-memory byte array mode)\n\n' >> benchmarks.md
cat $BENCH_DATA_MODE_FILE >> benchmarks.md
rm $BENCH_DATA_MODE_FILE
echo -en '\n' >> benchmarks.md
echo -en '#### Rust variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_RUST_DATA_MODE}\n\n" >> benchmarks.md
echo -en '#### C variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_GDB_DATA_MODE}\n\n" >> benchmarks.md
echo -en '### Unicode chars search, complete file scan (file stream mode)\n\n' >> benchmarks.md
cat $BENCH_UNICODE_FILE_MODE_FILE >> benchmarks.md
rm $BENCH_UNICODE_FILE_MODE_FILE
echo -en '\n' >> benchmarks.md
echo -en '#### Rust variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_RUST_UNICODE_FILE_MODE}\n\n" >> benchmarks.md
echo -en '#### C variant memory usage and context switches\n\n' >> benchmarks.md
echo -en "${TIME_OUTPUT_GDB_UNICODE_FILE_MODE}\n\n" >> benchmarks.md