78 lines
2.6 KiB
Text
78 lines
2.6 KiB
Text
![]() |
def main [benchmark_size:int=5] -> table {
|
||
|
let date = date now | format date '%F_%H-%M-%S'
|
||
|
let res_dir = $'build_results_($date)'
|
||
|
mkdir $res_dir
|
||
|
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 csv_results = []
|
||
|
for i in 1..$benchmark_size {
|
||
|
echo $'Build ($i) out of ($benchmark_size) for branch ($entry.tag)'
|
||
|
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
|
||
|
}
|
||
|
$csv_results = ($csv_results ++ [['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]
|
||
|
]
|
||
|
echo $'Finieshed building ($benchmark_size) images for branch ($entry.tag)'
|
||
|
echo $'Results for branch ($entry.tag):'
|
||
|
echo $csv_results
|
||
|
$benchmark = ($benchmark ++ $row)
|
||
|
$csv_results | to csv | save -f $'./($res_dir)/($entry.tag).csv'
|
||
|
|
||
|
echo ''
|
||
|
}
|
||
|
|
||
|
git checkout main
|
||
|
$benchmark | to md --pretty | save -f benchmark.md
|
||
|
cp -rf $'./($res_dir)' $'./build_results'
|
||
|
rm -rf $'./($res_dir)'
|
||
|
git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]"
|
||
|
git push
|
||
|
return $benchmark
|
||
|
}
|