def main [benchmark_size:int=5] -> table { let date = date now | format date '%F_%H-%M-%S' echo $'build_results_($date)' mkdir $'build_results_($date)' let bench = [ ['tag', 'image']; # ['simple-dockerfile', 'react-simple], # ['multi-stage-dockerfile', 'react-multistage'], # ['node-alpine-dockerfile', 'react-multistage-alpine'], # ['nginx-dockerfile', 'react-nginx'], # ['nginx-alpine-dockerfile', 'react-nginx-alpine'], ['bun-rspack-dockerfile', 'react-bun-rspack'], ['nginx-distroless-dockerfile', 'react-nginx-distroless'] ] # let images = [ # 'node:18', # 'node:18-alpine' # 'nginx', # 'nginx:stable-alpine', # 'oven/bun', # 'cgr.dev/chainguard/nginx' # ] # echo 'Pulling all docker images in advance' # echo '' # for entry in $images { # docker pull $entry # echo '' # } # echo '' mut benchmark: table = [] for entry: record in $bench { echo $'Switching to branch ($entry.tag)' echo '' git checkout $entry.tag mut sum = 0ns mut max = 0ns mut min = 0ns mut json_result = [] for i in 1..$benchmark_size { let time = $'(timeit {docker build --no-cache -t $entry.image .})' | into duration $sum += $time if $max == 0ns or $time >= $max { $max = $time } if $min == 0ns or $time <= $min { $min = $time } $json_result = ($json_result ++ [['tag', 'image', 'time']; [$entry.tag, $entry.image, $time]]) } let row table = [ ['tag', 'image', 'image size', 'median_time', 'max_time', 'min_time', 'benchmark_size']; [$'($entry.tag)', $'($entry.image)', $"(docker image ls $entry.image | from ssv | get 0 | get SIZE)", ($sum / $benchmark_size), $max, $min, $benchmark_size] ] $benchmark = ($benchmark ++ $row) echo $json_result $json_result | to csv | save -f $'./build_results_($date)/($entry.tag).csv' } git checkout main $benchmark | to md --pretty | save -f benchmark.md cp -rf $'(pwd)/build_results_($date) (pwd)/build_results' # git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]" # git push return $benchmark }