From 32eeead621275606572aa727f0d724db5ab09ede Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Tue, 22 Oct 2024 16:36:50 +0200 Subject: [PATCH] use binaryen correctly --- wasm/test/bench.sh | 9 ++++++--- wasm/test/test.sh | 29 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/wasm/test/bench.sh b/wasm/test/bench.sh index db68d5d5d..d37f26867 100755 --- a/wasm/test/bench.sh +++ b/wasm/test/bench.sh @@ -19,7 +19,10 @@ bench() { # compile native and wasocaml ../../ocamlopt $UNSAFE -O3 ./${2}.ml > /dev/null # optimize wasocaml code - wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-tail-call --enable-nontrapping-float-to-int --traps-never-happen --skip-pass=inlining-optimizing a.out.wasm -o a.out.wasm -O3 + cat a.out.wat | grep -v "^ (export" > a.out.noexport.wat + WASMOPT="wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-tail-call --enable-nontrapping-float-to-int --traps-never-happen -O3 --abstract-type-refining --cfp --coalesce-locals --closed-world --type-ssa --gufa-optimizing --type-merging --strip-debug --strip-dwarf --strip-producers --strip-target-features --type-refining --unsubtyping --vacuum --tuple-optimization --ssa --simplify-locals --simplify-globals-optimizing --signature-refining --signature-pruning --roundtrip --reorder-locals --reorder-globals --reorder-functions --remove-unused-types --remove-unused-names --remove-unused-module-elements --remove-unused-brs --remove-memory --precompute --optimize-instructions --optimize-casts --once-reduction --monomorphize --minimize-rec-groups --merge-similar-functions --merge-locals --merge-blocks --local-subtyping --local-cse --licm --intrinsic-lowering --inlining-optimizing --heap-store-optimization --gto --gsi --global-refining --duplicate-import-elimination --duplicate-function-elimination --directize --dce --dae-optimizing" + # TODO: try --flatten ; --rereloop ; --precompute-propagate ; --dfo + $WASMOPT -o a.out.wasm a.out.noexport.wat # compile bytecode ocamlc $UNSAFE ./${2}.ml -o a.out.bc > /dev/null # compile wsoo @@ -28,7 +31,7 @@ bench() { js_of_ocaml compile --target-env=nodejs --opt=3 ./a.out.bc -o a.jsoo.bc.js # bench - hyperfine --runs 3 \ + hyperfine --warmup 3 --runs 5 \ -n "OCaml native" "./a.out" \ -n "Wasocaml" "${NODE} ./main_node.mjs" \ -n "Wsoo" "${NODE} ./a.wsoo.bc.js" \ @@ -39,7 +42,7 @@ bench() { } -#bench "Almabench" "almabench" # global init must have correct type +#bench "Almabench" "almabench" # we must change the declared type of exports from FloatArray to Blockfloat_n with the righ n # then it gives an unreachable #bench "Binary Trees" "binary_trees" # unreachable #bench "Boyer" "boyer" # unreachable #bench "Boyer no exceptions" "boyer_no_exc" # unreachable diff --git a/wasm/test/test.sh b/wasm/test/test.sh index 5690b3ead..2dfb58a97 100755 --- a/wasm/test/test.sh +++ b/wasm/test/test.sh @@ -5,34 +5,36 @@ set -eu ULIMIT_STACK_SIZE=20000 STACK_SIZE=10000 NODE="node-canary --stack-size=${STACK_SIZE}" +alias time='/usr/bin/time -f"real %e user %U sys %S"' ulimit -s $ULIMIT_STACK_SIZE -#UNSAFE="-unsafe" +#UNSAFE="-unsafe" # TODO: this requires the prim mod primitives UNSAFE="" bench_native() { echo -n " OCaml native: " ocamlopt $UNSAFE -O3 ./${2}.ml > /dev/null - ./a.out > output_${2}_ocaml_native.txt - echo "OK" + time ./a.out > output_${2}_ocaml_native.txt } bench_wasocaml_opt() { echo -n " Wasocaml + wasm-opt (node): " ../../ocamlopt $UNSAFE -O3 ./${2}.ml > /dev/null - wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-tail-call --enable-nontrapping-float-to-int --traps-never-happen --skip-pass=inlining-optimizing a.out.wasm -o a.out.wasm -O3 - $NODE ./main_node.mjs > output_${2}_wasocaml_opt.txt + cat a.out.wat | grep -v "^ (export" > a.out.noexport.wat + WASMOPT="wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-tail-call --enable-nontrapping-float-to-int --traps-never-happen -O3 --abstract-type-refining --cfp --coalesce-locals --closed-world --type-ssa --gufa-optimizing --type-merging --strip-debug --strip-dwarf --strip-producers --strip-target-features --type-refining --unsubtyping --vacuum --tuple-optimization --ssa --simplify-locals --simplify-globals-optimizing --signature-refining --signature-pruning --roundtrip --reorder-locals --reorder-globals --reorder-functions --remove-unused-types --remove-unused-names --remove-unused-module-elements --remove-unused-brs --remove-memory --precompute --optimize-instructions --optimize-casts --once-reduction --monomorphize --minimize-rec-groups --merge-similar-functions --merge-locals --merge-blocks --local-subtyping --local-cse --licm --intrinsic-lowering --inlining-optimizing --heap-store-optimization --gto --gsi --global-refining --duplicate-import-elimination --duplicate-function-elimination --directize --dce --dae-optimizing" + # TODO: try --flatten ; --rereloop ; --precompute-propagate ; --dfo + $WASMOPT -o a.out.wasm a.out.noexport.wat + $WASMOPT -S -o a.out.wat a.out.wasm + time $NODE ./main_node.mjs > output_${2}_wasocaml_opt.txt diff output_${2}_ocaml_native.txt output_${2}_wasocaml_opt.txt - echo "OK" } bench_wasocaml() { echo -n " Wasocaml (node): " ../../ocamlopt $UNSAFE -O3 ./${2}.ml > /dev/null - $NODE ./main_node.mjs > output_${2}_wasocaml.txt + time $NODE ./main_node.mjs > output_${2}_wasocaml.txt diff output_${2}_ocaml_native.txt output_${2}_wasocaml.txt - echo "OK" } bench_wsoo() { @@ -40,9 +42,8 @@ bench_wsoo() { ocamlc $UNSAFE ./${2}.ml > /dev/null rm -rf a.assets* a.js a.wat || true 2> /dev/null wasm_of_ocaml compile --opt=3 ./a.out > /dev/null - $NODE ./a.js > output_${2}_wsoo.txt + time $NODE ./a.js > output_${2}_wsoo.txt diff output_${2}_ocaml_native.txt output_${2}_wsoo.txt - echo "OK" } bench_jsoo() { @@ -50,17 +51,15 @@ bench_jsoo() { ocamlc $UNSAFE ./${2}.ml > /dev/null rm -f a.js a.wat || true 2> /dev/null js_of_ocaml compile --target-env=nodejs --opt=3 ./a.out - $NODE ./a.js > output_${2}_jsoo.txt + time $NODE ./a.js > output_${2}_jsoo.txt diff output_${2}_ocaml_native.txt output_${2}_jsoo.txt - echo "OK" } bench_bytecode() { echo -n " OCaml bytecode: " ocamlc $UNSAFE ./${2}.ml > /dev/null - ocamlrun ./a.out > output_${2}_bytecode.txt + time ocamlrun ./a.out > output_${2}_bytecode.txt diff output_${2}_ocaml_native.txt output_${2}_bytecode.txt - echo "OK" } bench() { @@ -70,7 +69,7 @@ bench() { bench_native "${1}" "${2}" bench_wasocaml_opt "${1}" "${2}" - bench_wasocaml "${1}" "${2}" + #bench_wasocaml "${1}" "${2}" bench_wsoo "${1}" "${2}" bench_jsoo "${1}" "${2}" bench_bytecode "${1}" "${2}"