summaryrefslogtreecommitdiff
path: root/comp_bench
blob: 22bb906c6972462ba44129aca79e107445f0d4fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

[ "$1" = -v ] && verbose=1

set -e

do_time() {
    exec 3>&1
    (time "$@") 2>&1 >&3 | grep . >&2
}

do_bench() {
    tmpfile=
    trap '[ -n "$tmpfile" ] && rm -f "$tmpfile"' HUP INT QUIT TERM EXIT
    tmpfile=$(mktemp)
    [ -z "$verbose" ] || printf '%s compression:\n' "$1"
    ${verbose+do_time} "$@" -c <initramfs.img >"$tmpfile"
    printf '%s size: %s bytes\n' "$1" "$(wc -c < "$tmpfile")"
    printf '%s decompression:\n' "$1"
    do_time "$1" -dc <"$tmpfile" >/dev/null
    rm "$tmpfile"
    trap '' EXIT
    echo
}

if [ -e initramfs.img ] && [ "$(file -b initramfs.img)" != "ASCII cpio archive (SVR4 with no CRC)" ]; then
    echo "warning: overwriting initramfs.img" >&2
    COMPRESSOR=cat ./make
fi
do_bench gzip -9
do_bench bzip2 -9
do_bench lzma -9e --check=crc32
do_bench xz --check=crc32 --x86 --lzma2=preset=9e
do_bench lzop -9
do_bench lz4 --best --favor-decSpeed -l
do_bench zstd -19