Skip to content

Commit

Permalink
Add aot measure in benchmark (#74)
Browse files Browse the repository at this point in the history
* add aot measure in benchmark script

---------

Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu authored Nov 27, 2023
1 parent 7d999ac commit 6d7be01
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
14 changes: 14 additions & 0 deletions tests/benchmark/fibonacci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This file is generated by tsc */
"use strict";
function fibonacci(num) {
if (num < 2) {
return num;
}
else {
return fibonacci(num - 1) + fibonacci(num - 2);
}
}
function main() {
fibonacci(35);
}
main()
16 changes: 16 additions & 0 deletions tests/benchmark/fibonacci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

function fibonacci(num: number): number {
if (num < 2) {
return num;
} else {
return fibonacci(num - 1) + fibonacci(num - 2);
}
}

export function main() {
fibonacci(35);
}
51 changes: 32 additions & 19 deletions tests/benchmark/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ benchmark_dir=$(cd "$(dirname "$0")" && pwd)
benchmarks=$(ls $benchmark_dir)
ts2wasm_script=$benchmark_dir/../../build/cli/ts2wasm.js
iwasm_gc=$benchmark_dir/../../runtime-library/build/iwasm_gc
wamrc=$benchmark_dir/../../runtime-library/deps/wamr-gc/wamr-compiler/build/wamrc
optimize_level=3

QJS_CMD=`which qjs`
Expand All @@ -28,8 +29,20 @@ fi

ts_times=()
js_times=()
aot_times=()
prefixs=()

tmp_total_second=0
process_time_info() {
time_info=$(cat time_output.txt)
echo "$time_info"
real_time=$(echo "$time_info" | grep "real" | awk '{print $2}')
minutes=$(echo "$real_time" | cut -dm -f1)
seconds=$(echo "$real_time" | cut -dm -f2 | sed 's/s//')
echo ""
tmp_total_second=$(bc <<< "$minutes * 60 + $seconds")
}

for benchmark in $benchmarks; do
if [ -f "$benchmark" ]; then
filename=$(basename "$benchmark")
Expand All @@ -42,41 +55,41 @@ for benchmark in $benchmarks; do

if [ "$extension" = "ts" ]; then
prefixs+=($prefix)
echo "Run $prefix benchmark by WAMR:"
echo "Run $prefix benchmark by WAMR interpreter:"
node $ts2wasm_script $benchmark_dir/$benchmark --opt ${optimize_level} --output $prefix.wasm > tmp.txt
{ time $iwasm_gc --gc-heap-size=52428800 -f main $prefix.wasm; } 2> time_output.txt
elif [ "$extension" = "js" ]; then
echo "Run $prefix benchmark by qjs:"
{ time $qjs $benchmark_dir/$benchmark; } 2> time_output.txt
fi
process_time_info
ts_times+=($tmp_total_second)

if [ "$extension" = "ts" ] || [ "$extension" = "js" ]; then
time_info=$(cat time_output.txt)
echo "$time_info"
real_time=$(echo "$time_info" | grep "real" | awk '{print $2}')
minutes=$(echo "$real_time" | cut -dm -f1)
seconds=$(echo "$real_time" | cut -dm -f2 | sed 's/s//')
total_seconds=$(bc <<< "$minutes * 60 + $seconds")
fi
echo "Run $prefix benchmark by WAMR aot:"
$wamrc --enable-gc -o $prefix.aot $prefix.wasm > tmp.txt
{ time $iwasm_gc --gc-heap-size=52428800 -f main $prefix.aot; } 2> time_output.txt
process_time_info
aot_times+=($tmp_total_second)

if [ "$extension" = "ts" ]; then
ts_times+=($total_seconds)
elif [ "$extension" = "js" ]; then
js_times+=($total_seconds)
echo "Run $prefix benchmark by qjs:"
{ time $qjs $benchmark_dir/$benchmark; } 2> time_output.txt
process_time_info
js_times+=($tmp_total_second)
fi

echo ""
fi
done

rm -rf *.txt
rm -rf *.wasm
rm -rf *.wat
rm -rf *.aot

for ((i = 0; i < ${#ts_times[@]}; i++)); do
ts_time=${ts_times[$i]}
js_time=${js_times[$i]}
aot_time=${aot_times[$i]}
ratio=$(bc -l <<< "scale=2; $ts_time / $js_time")
formatted_result=$(printf "%.2f" "$ratio")
echo "Time ratio for ${prefixs[$i]} benchmark (WAMR/qjs): $formatted_result"
echo "Time ratio for ${prefixs[$i]} benchmark (WAMR_interpreter/qjs): $formatted_result"
ratio_aot=$(bc -l <<< "scale=2; $aot_time / $js_time")
formatted_result_aot=$(printf "%.2f" "$ratio_aot")
echo "Time ratio for ${prefixs[$i]} benchmark (WAMR_aot/qjs): $formatted_result_aot"
echo ""
done

0 comments on commit 6d7be01

Please sign in to comment.