Skip to content

Commit

Permalink
[benchmarks/compute] Refactor to simplify and start using time_.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jul 29, 2020
1 parent ef9ea27 commit 48aebcf
Showing 1 changed file with 71 additions and 51 deletions.
122 changes: 71 additions & 51 deletions benchmarks/compute.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ readonly OSH_CC=_bin/osh_eval.opt.stripped
TIMEFORMAT='%U'

# task_name,iter,args
tasks() {
fib-tasks() {
cat <<EOF
fib py 200 44
fib bash 200 44
fib dash 200 44
fib $OSH_CC 200 44
fib python 200 44
fib bash 200 44
fib dash 200 44
fib $OSH_CC 200 44
EOF
}

word_freq-tasks() {
cat <<EOF
word_freq python 10 configure
word_freq bash 10 configure
word_freq $OSH_CC 10 configure
EOF
}

Expand All @@ -59,7 +67,9 @@ EOF
# task, task args -- I guess these can be space separated
# stdout md5sum -- so it's correct! Because I did catch some problems earlier.

compute-task() {
readonly -a TIME_PREFIX=(benchmarks/time_.py --tsv --append)

fib-one() {
# TODO: follow parser-task, and get all the args above.
# And also need a shell functions to save the stdout md5sum? Needs to be a
# field too. benchmarks/time.py gets a bunch of --field arguments. Does it
Expand All @@ -70,71 +80,81 @@ compute-task() {
local runtime=$2
shift 2

local out=_tmp/compute/$name
mkdir -p $out

local -a TIME_PREFIX=(benchmarks/time_.py --tsv --append -o $out/times.tsv)

local ext
case $runtime in
(py)
"${TIME_PREFIX[@]}" --stdout $out/py.txt --field $runtime -- \
benchmarks/compute/$name.py "$@"
(python)
ext='py'
;;
(*sh | *osh*)
local file=$(basename $runtime)
"${TIME_PREFIX[@]}" --stdout $out/$file.txt --field $runtime -- \
$runtime benchmarks/compute/$name.sh "$@"
ext='sh'
;;
esac
}

fib-all() {
local times=_tmp/compute/fib/times.tsv
rm -f $times

tasks | while read name runtime args; do
compute-task $name $runtime $args # relies on splitting
done
#md5sum _tmp/compute/fib/*

wc -l _tmp/compute/fib/*
cat $times
$runtime benchmarks/compute/$name.$ext "$@"
}

fib-demo() {
local iters=200
word_freq-one() {
local name=${1:-word_freq}
local runtime=$2

echo --- python
time benchmarks/compute/fib.py $iters 44 | wc -l
local iters=${3:-10}
local in=${4:-configure} # input

for sh in dash bash $OSH_CC; do
echo --- $sh
time $sh benchmarks/compute/fib.sh $iters 44 | wc -l
done
local ext
case $runtime in
(python)
ext='py'
;;
(*sh | *osh*)
ext='sh'
;;
esac

$runtime benchmarks/compute/word_freq.$ext $iters < $in | sort -n
}

word-freq-demo() {
local iters=10
#
# Helpers
#

#local in=README.md # breaks on the * characters!
local in=configure # still doesn't work because of / and \ chars
word-freq-all() { task-all word_freq; }
fib-all() { task-all fib; }

task-all() {
local name=$1

local out=_tmp/compute
local out=_tmp/compute/$name
mkdir -p $out

echo --- python
time benchmarks/compute/word_freq.py $iters < $in | sort -n > $out/py.txt
local times=$out/times.tsv
rm -f $times

# TODO: bash isn't correct!
#for sh in $OSH_CC; do
for sh in bash $OSH_CC; do
# 2 seconds
echo --- $sh
time $sh benchmarks/compute/word_freq.sh $iters < $in | sort -n > $out/$(basename $sh).txt
# header
echo $'status\telapsed\tstdout_md5sum\truntime\ttask_name\ttask_args' > $times

local name=${1:-'word-freq'}

${name}-tasks | while read _ runtime args; do
local file
case $runtime in
(python)
file='py'
;;
(*sh | *osh*)
file=$(basename $runtime)
;;
esac

# join args into a single field
"${TIME_PREFIX[@]}" \
--stdout $out/$file.txt -o $out/times.tsv \
--field $runtime --field "$name" --field "$args" -- \
$0 ${name}-one "$name" "$runtime" $args # relies on splitting
done

md5sum $out/*
#wc -l _tmp/compute/word_freq/*
tree $out
cat $times
}

# TODO: Fix the OSH comparison operator! It gives the wrong answer and
Expand Down

0 comments on commit 48aebcf

Please sign in to comment.