react-docker-optimization/bench_results.nu
2025-01-12 21:03:07 +01:00

73 lines
3 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_build_time: duration, max_build_time: duration, min_build_time: duration, total_build_time: duration, max_size: string, build_benchmark_size: int, median_startup_time: duration, max_startup_time: duration, min_startup_time: duration, total_startup_time: duration, startup_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 build_filename = './build_results/' + $entry.tag + '.csv'
let bench_res = open $build_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 startup_filename = './start_results/' + $entry.tag + '.csv'
let bench_res_startup = open $startup_filename
let $startup_size = $bench_res_startup | length
mut sum_s = 0ns
mut max_s = 0ns
mut min_s = 0ns
for res in $bench_res_startup {
let time = $res | get time | into duration
$sum_s += $time
if $max_s == 0ns or $time >= $max_s {
$max_s = $time
}
if $min_s == 0ns or $time <= $min_s {
$min_s = $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_build_time: duration, max_build_time: duration, min_build_time: duration, total_build_time: duration, max_size: string, build_benchmark_size: int, median_startup_time: duration, max_startup_time: duration, min_startup_time: duration, total_startup_time: duration, startup_benchmark_size: int> = [
['tag', 'image', 'image_size', 'median_build_time', 'max_build_time', 'min_build_time', 'total_build_time', 'max_size', 'build_benchmark_size', 'median_startup_time', 'max_startup_time', 'min_startup_time', 'total_startup_time', 'startup_benchmark_size'];
[$'($entry.tag)', $'($entry.image)', $image_size, ($sum / $benchmark_size), $max, $min, $sum, ($image_size * $benchmark_size), $benchmark_size, ($sum_s / $startup_size), $max_s, $min_s, $sum_s, $startup_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