react-docker-optimization/bench_results.nu
2025-01-10 16:06:26 +01:00

55 lines
1.9 KiB
Text

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']
]
for entry in $bench {
echo $'Switching to branch ($entry.tag)'
echo ''
git checkout $entry.tag
docker build -t $entry.image .
}
mut benchmark: table<tag: string, image: string, image_size: string, median_time: duration, max_time: duration, min_time: duration, total_time: duration, max_space: string, benchmark_size: int> = []
git checkout main
for entry: record<tag: string, image:string> in $bench {
mut sum = 0ns
mut max = 0ns
mut min = 0ns
let filename = './build_results' + $entry.tag + '.csv'
echo $filename
let bench_res = open $filename
let $benchmark_size = $bench_res | length
for res in $bench_res {
let time = $res | get time | into duration
$sum += $time
if $max == 0ns or $time >= $max {
$max = $time
}
if $min == 0ns or $time <= $min {
$min = $time
}
}
let image_size = docker image ls $entry.image | from ssv | get 0 | get SIZE | into filesize
let row table<tag: string, image: string, 'image size': string, median_time: duration, max_time: duration, min_time: duration, total_time: duration, benchmark_size: int> = [
['tag', 'image', 'image_size', 'median_time', 'max_time', 'min_time', 'total_time', 'max_size', 'benchmark_size'];
[$'($entry.tag)', $'($entry.image)', $image_size, ($sum / $benchmark_size), $max, $min, $sum, ($image_size * $benchmark_size), $benchmark_size]
]
$benchmark = ($benchmark ++ $row)
}
$benchmark | to md --pretty | save -f benchmark.md
# git add .
# git commit -m $"updated README for benchmarks (date now | format date '%+') [CI SKIP]"
# git push