-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#! /bin/sh | ||
|
||
set -e | ||
trap "exit" SIGINT SIGTERM # exit from loop | ||
|
||
cd "$(dirname "$0")" | ||
huniq2bin="./target/release/huniq" | ||
huniq1dir="./target/benchmark/huniq1" | ||
huniq1bin="${huniq1dir}/huniq" | ||
|
||
measure() { | ||
env time -f'%e %M' "$@" >/dev/null | ||
} | ||
|
||
bench_rust() { | ||
measure ./target/release/huniq "$@" | ||
} | ||
|
||
bench_cpp() { | ||
measure "$huniq1bin" "$@" | ||
} | ||
|
||
bench_shell() { | ||
if [[ "$@" = "" ]]; then | ||
measure sort -u | ||
else | ||
{ | ||
measure sort | measure uniq | ||
} 2>&1 | awk ' | ||
{ | ||
elapsed=$1; | ||
mem+=$2; | ||
} | ||
END { | ||
print(elapsed, mem); | ||
}' | ||
fi | ||
} | ||
|
||
main() { | ||
test -e "$huniq2bin" || { | ||
cargo build --release | ||
} | ||
|
||
test -e "$huniq1dir" || { | ||
git clone --recursive "https://github.com/SoftwearDevelopment/huniq" "$huniq1dir" | ||
} >&2 | ||
|
||
test -e "$huniq1bin" || { | ||
cd "$huniq1dir" | ||
make | ||
cd - | ||
} >&2 | ||
|
||
declare -A modeargs | ||
modeargs[uniq]="" | ||
modeargs[count]="-c" | ||
|
||
while true; do | ||
for mode in "uniq" "count"; do | ||
for repeats in 1 2 5 10 50 100; do | ||
for impl in rust cpp shell; do | ||
echo -n "$mode $repeats $impl " | ||
yes | head -n "$repeats" | while read _; do cat /usr/share/dict/*; done \ | ||
| "bench_${impl}" ${modeargs[${mode}]} | ||
done | ||
done | ||
done | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
uniq 1 rust uniq 1 cpp uniq 1 shell uniq 2 rust uniq 2 cpp uniq 2 shell uniq 5 rust uniq 5 cpp uniq 5 shell uniq 10 rust uniq 10 cpp uniq 10 shell uniq 50 rust uniq 50 cpp uniq 50 shell uniq 100 rust uniq 100 cpp uniq 100 shell count 1 rust count 1 cpp count 1 shell 9.97 11332 | ||
count 2 rust count 2 cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#! /bin/bash | ||
|
||
cd "$(dirname "$0")" | ||
bin="./target/debug/huniq" | ||
|
||
failures=0 | ||
count=0 | ||
|
||
assert() { | ||
local desc="$1"; shift | ||
local ref="$1"; shift | ||
|
||
(( count++ )) | ||
diff <(eval "$@") "$ref" >/dev/null || { | ||
echo >&2 "Assertion failed \"$desc\": \`$@\`" | ||
diff <(eval "$@") "$ref" >&2 | ||
(( failures++ )) | ||
} | ||
} | ||
|
||
main() { | ||
test -e "$huniq2bin" || { | ||
cargo build | ||
} | ||
|
||
assert uniq test/expect_uniq.txt "$bin <test/input.txt" | ||
assert count test/expect_count.txt "$bin -c <test/input.txt | sort -nr" | ||
|
||
echo >&2 "$count tests $failures failures" | ||
test "$failures" -eq 0 | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
3 hello | ||
2 bar | ||
1 foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hello | ||
foo | ||
bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hello | ||
foo | ||
hello | ||
hello | ||
bar | ||
bar |