Move kraken,scheme,python,cpp fib tests over to koka_bench, add WAVM as a tested compiler backend for the Kraken benchmarks
This commit is contained in:
@@ -15,3 +15,6 @@ add_subdirectory(haskell)
|
||||
add_subdirectory(java)
|
||||
add_subdirectory(ocaml)
|
||||
add_subdirectory(swift)
|
||||
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(scheme)
|
||||
|
||||
8
koka_bench/copy_wrapper.sh
Executable file
8
koka_bench/copy_wrapper.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
OUR_DIR="$(dirname $(readlink -f $0))"
|
||||
SOURCE="$1"
|
||||
OUT_DIR="$2"
|
||||
OUT_NAME="$3"
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
cp $SOURCE "$OUT_DIR/$OUT_NAME"
|
||||
@@ -2,7 +2,7 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
||||
set(CMAKE_CXX_EXTENSIONS NO)
|
||||
|
||||
foreach (source IN ITEMS rbtree.cpp nqueens.cpp cfold.cpp deriv.cpp)
|
||||
foreach (source IN ITEMS rbtree.cpp nqueens.cpp cfold.cpp deriv.cpp fib.cpp)
|
||||
get_filename_component(name "${source}" NAME_WE)
|
||||
set(name "cpp-${name}")
|
||||
|
||||
|
||||
17
koka_bench/cpp/fib.cpp
Normal file
17
koka_bench/cpp/fib.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
int fib(int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
} else if (n == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
printf("%d\n", fib(atoi(argv[1])));
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
set(sources rbtree.kk nqueens.kk nqueens-int.kk cfold.kk deriv.kk)
|
||||
set(sources rbtree.kk nqueens.kk nqueens-int.kk cfold.kk deriv.kk fib.kk)
|
||||
|
||||
set(koka koka)
|
||||
|
||||
|
||||
13
koka_bench/koka/fib.kk
Normal file
13
koka_bench/koka/fib.kk
Normal file
@@ -0,0 +1,13 @@
|
||||
module nqueens
|
||||
import std/num/int32
|
||||
import std/os/env
|
||||
|
||||
|
||||
pub fun fib( n : int ) : div int
|
||||
match n
|
||||
0 -> 1
|
||||
1 -> 1
|
||||
x -> fib(x - 1) + fib(x - 2)
|
||||
|
||||
pub fun main()
|
||||
fib(get-args().head("").parse-int.default(30)).println
|
||||
@@ -1,4 +1,4 @@
|
||||
set(sources rbtree.kp rbtree-opt.kp nqueens.kp cfold.kp deriv.kp)
|
||||
set(sources rbtree.kp rbtree-opt.kp nqueens.kp cfold.kp deriv.kp fib.kp fib-let.kp)
|
||||
|
||||
set(kraken "../../kraken_wrapper.sh")
|
||||
|
||||
|
||||
38
koka_bench/kraken/fib-let.kp
Normal file
38
koka_bench/kraken/fib-let.kp
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
((wrap (vau root_env (quote)
|
||||
((wrap (vau (let1)
|
||||
(let1 lambda (vau se (p b1) (wrap (eval (array vau p b1) se)))
|
||||
(let1 current-env (vau de () de)
|
||||
(let1 cons (lambda (h t) (concat (array h) t))
|
||||
(let1 Y (lambda (f3)
|
||||
((lambda (x1) (x1 x1))
|
||||
(lambda (x2) (f3 (wrap (vau app_env (& y) (lapply (x2 x2) y app_env)))))))
|
||||
(let1 vY (lambda (f)
|
||||
((lambda (x3) (x3 x3))
|
||||
(lambda (x4) (f (vau de1 (& y) (vapply (x4 x4) y de1))))))
|
||||
(let1 let (vY (lambda (recurse) (vau de2 (vs b) (cond (= (len vs) 0) (eval b de2)
|
||||
true (vapply let1 (array (idx vs 0) (idx vs 1) (array recurse (slice vs 2 -1) b)) de2)))))
|
||||
(let (
|
||||
lcompose (lambda (g f) (lambda (& args) (lapply g (array (lapply f args)))))
|
||||
rec-lambda (vau se (n p b) (eval (array Y (array lambda (array n) (array lambda p b))) se))
|
||||
|
||||
fib (rec-lambda fib (n) (cond (= 0 n) 1
|
||||
(= 1 n) 1
|
||||
true (let (
|
||||
fib_minus_1 (fib (- n 1))
|
||||
fib_minus_2 (fib (- n 2))
|
||||
) (+ fib_minus_1 fib_minus_2))))
|
||||
|
||||
monad (array 'write 1 (str "running fib") (vau (written code)
|
||||
(array 'args (vau (args code)
|
||||
(array 'exit (fib (read-string (idx args 1))))
|
||||
))
|
||||
))
|
||||
|
||||
) monad)
|
||||
; end of all lets
|
||||
))))))
|
||||
; impl of let1
|
||||
)) (vau de (s v b) (eval (array (array wrap (array vau (array s) b)) v) de)))
|
||||
; impl of quote
|
||||
)) (vau (x5) x5))
|
||||
35
koka_bench/kraken/fib.kp
Normal file
35
koka_bench/kraken/fib.kp
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
((wrap (vau root_env (quote)
|
||||
((wrap (vau (let1)
|
||||
(let1 lambda (vau se (p b1) (wrap (eval (array vau p b1) se)))
|
||||
(let1 current-env (vau de () de)
|
||||
(let1 cons (lambda (h t) (concat (array h) t))
|
||||
(let1 Y (lambda (f3)
|
||||
((lambda (x1) (x1 x1))
|
||||
(lambda (x2) (f3 (wrap (vau app_env (& y) (lapply (x2 x2) y app_env)))))))
|
||||
(let1 vY (lambda (f)
|
||||
((lambda (x3) (x3 x3))
|
||||
(lambda (x4) (f (vau de1 (& y) (vapply (x4 x4) y de1))))))
|
||||
(let1 let (vY (lambda (recurse) (vau de2 (vs b) (cond (= (len vs) 0) (eval b de2)
|
||||
true (vapply let1 (array (idx vs 0) (idx vs 1) (array recurse (slice vs 2 -1) b)) de2)))))
|
||||
(let (
|
||||
lcompose (lambda (g f) (lambda (& args) (lapply g (array (lapply f args)))))
|
||||
rec-lambda (vau se (n p b) (eval (array Y (array lambda (array n) (array lambda p b))) se))
|
||||
|
||||
fib (rec-lambda fib (n) (cond (= 0 n) 1
|
||||
(= 1 n) 1
|
||||
true (+ (fib (- n 1)) (fib (- n 2)))))
|
||||
|
||||
monad (array 'write 1 (str "running fib") (vau (written code)
|
||||
(array 'args (vau (args code)
|
||||
(array 'exit (fib (read-string (idx args 1))))
|
||||
))
|
||||
))
|
||||
|
||||
) monad)
|
||||
; end of all lets
|
||||
))))))
|
||||
; impl of let1
|
||||
)) (vau de (s v b) (eval (array (array wrap (array vau (array s) b)) v) de)))
|
||||
; impl of quote
|
||||
)) (vau (x5) x5))
|
||||
@@ -10,7 +10,14 @@ mv ./csc_out.wasm "$OUT_DIR/$OUT_NAME.wasm"
|
||||
printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME"'.wasm" $@' > "$OUT_DIR/$OUT_NAME"
|
||||
chmod 755 "$OUT_DIR/$OUT_NAME"
|
||||
|
||||
printf '#!/usr/bin/env bash\nWAVM_OBJECT_CACHE_DIR=$(pwd) wavm run "$(dirname $(readlink -f $0))/'"$OUT_NAME"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-wavm"
|
||||
chmod 755 "$OUT_DIR/$OUT_NAME-wavm"
|
||||
|
||||
|
||||
scheme --script "$OUR_DIR/../partial_eval.scm" $SOURCE no_compile
|
||||
mv ./csc_out.wasm "$OUT_DIR/$OUT_NAME-slow.wasm"
|
||||
printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME-slow"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-slow"
|
||||
chmod 755 "$OUT_DIR/$OUT_NAME-slow"
|
||||
|
||||
printf '#!/usr/bin/env bash\nWAVM_OBJECT_CACHE_DIR=$(pwd) wavm run "$(dirname $(readlink -f $0))/'"$OUT_NAME-slow"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-slow-wavm"
|
||||
chmod 755 "$OUT_DIR/$OUT_NAME-slow-wavm"
|
||||
|
||||
22
koka_bench/python/CMakeLists.txt
Normal file
22
koka_bench/python/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
set(copy_wrapper "../../copy_wrapper.sh")
|
||||
|
||||
set(sources python-fib.py python-fib-let.py)
|
||||
foreach (source IN LISTS sources)
|
||||
|
||||
get_filename_component(name "${source}" NAME_WE)
|
||||
|
||||
set(out_dir "${CMAKE_CURRENT_BINARY_DIR}/out/bench")
|
||||
set(out_path "${out_dir}/${name}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${out_path}
|
||||
COMMAND ${copy_wrapper} "${CMAKE_CURRENT_SOURCE_DIR}/${source}" ${out_dir} ${name}
|
||||
DEPENDS ${source}
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(update-${name} ALL DEPENDS "${out_path}")
|
||||
add_executable(${name}-exe IMPORTED)
|
||||
set_target_properties(${name}-exe PROPERTIES IMPORTED_LOCATION "${out_path}")
|
||||
endforeach ()
|
||||
|
||||
13
koka_bench/python/python-fib-let.py
Executable file
13
koka_bench/python/python-fib-let.py
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
def fib(n):
|
||||
if n == 0:
|
||||
return 1
|
||||
elif n == 1:
|
||||
return 1
|
||||
else:
|
||||
r1 = fib(n-1)
|
||||
r2 = fib(n-2)
|
||||
return r1 + r2
|
||||
print(fib(int(sys.argv[1])))
|
||||
11
koka_bench/python/python-fib.py
Executable file
11
koka_bench/python/python-fib.py
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
def fib(n):
|
||||
if n == 0:
|
||||
return 1
|
||||
elif n == 1:
|
||||
return 1
|
||||
else:
|
||||
return fib(n-1) + fib(n-2)
|
||||
print(fib(int(sys.argv[1])))
|
||||
22
koka_bench/scheme/CMakeLists.txt
Normal file
22
koka_bench/scheme/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
set(copy_wrapper "../../copy_wrapper.sh")
|
||||
|
||||
set(sources scheme-fib.scm scheme-fib-let.scm)
|
||||
foreach (source IN LISTS sources)
|
||||
|
||||
get_filename_component(name "${source}" NAME_WE)
|
||||
|
||||
set(out_dir "${CMAKE_CURRENT_BINARY_DIR}/out/bench")
|
||||
set(out_path "${out_dir}/${name}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${out_path}
|
||||
COMMAND ${copy_wrapper} "${CMAKE_CURRENT_SOURCE_DIR}/${source}" ${out_dir} ${name}
|
||||
DEPENDS ${source}
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target(update-${name} ALL DEPENDS "${out_path}")
|
||||
add_executable(${name}-exe IMPORTED)
|
||||
set_target_properties(${name}-exe PROPERTIES IMPORTED_LOCATION "${out_path}")
|
||||
endforeach ()
|
||||
|
||||
8
koka_bench/scheme/scheme-fib-let.scm
Executable file
8
koka_bench/scheme/scheme-fib-let.scm
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env -S scheme --script
|
||||
(pretty-print ((letrec ((fib (lambda (n) (cond ((equal? n 0) 1)
|
||||
((equal? n 1) 1)
|
||||
(#t (let (
|
||||
(r1 (fib (- n 1)))
|
||||
(r2 (fib (- n 2)))
|
||||
) (+ r1 r2)))))))
|
||||
fib) (read (open-input-string (list-ref (command-line) 1)))))
|
||||
5
koka_bench/scheme/scheme-fib.scm
Executable file
5
koka_bench/scheme/scheme-fib.scm
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S scheme --script
|
||||
(pretty-print ((letrec ((fib (lambda (n) (cond ((equal? n 0) 1)
|
||||
((equal? n 1) 1)
|
||||
(#t (+ (fib (- n 1)) (fib (- n 2))))))))
|
||||
fib) (read (open-input-string (list-ref (command-line) 1)))))
|
||||
@@ -16,16 +16,18 @@ mkdir -p slow
|
||||
find build -type f -name \*slow\* -exec mv {} slow \;
|
||||
cp ./build/kraken/out/bench/kraken-* ./slow
|
||||
|
||||
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*fib\* -printf "\"%p 30\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown fib_table.md --export-csv fib_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*nqueens\* -printf "\"%p 10\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown nqueens_table.md --export-csv nqueens_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*rbtree\* -printf "\"%p 42000\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown rbtree_table.md --export-csv rbtree_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown cfold_table.md --export-csv cfold_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*deriv\* -printf "\"%p 8\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown deriv_table.md --export-csv deriv_table.csv'
|
||||
|
||||
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*nqueens\* -printf "\"%p 7\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_nqueens_table.md --export-csv slow_nqueens_table.csv'
|
||||
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_cfold_table.md --export-csv slow_cfold_table.csv'
|
||||
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*deriv\* -printf "\"%p 3\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_deriv_table.md --export-csv slow_deriv_table.csv'
|
||||
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*rbtree\* -printf "\"%p 100\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_rbtree_table.md --export-csv slow_rbtree_table.csv'
|
||||
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*nqueens\* -printf "\"%p 7\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_nqueens_table.md --export-csv slow_nqueens_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_cfold_table.md --export-csv slow_cfold_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*deriv\* -printf "\"%p 3\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_deriv_table.md --export-csv slow_deriv_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*rbtree\* -printf "\"%p 100\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_rbtree_table.md --export-csv slow_rbtree_table.csv'
|
||||
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*fib\* -printf "\"%p 30\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_fib_table.md --export-csv slow_fib_table.csv'
|
||||
|
||||
for x in *_table.csv
|
||||
do
|
||||
|
||||
Reference in New Issue
Block a user