71 lines
2.4 KiB
Text
71 lines
2.4 KiB
Text
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<tag: string, image: string, 'image size': string, median_time: duration, max_time: duration, min_time: duration, benchmark_size: int> = []
|
|
|
|
for entry: record<tag: string, image:string> 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: string, image: string, 'image size': string, median_time: duration, max_time: duration, min_time: duration, benchmark_size: int> = [
|
|
['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)
|
|
$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 $'./build_results_($date)' $'./build_results'
|
|
rm -rf $'./build_results_($date)'
|
|
# git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]"
|
|
# git push
|
|
return $benchmark
|
|
}
|