forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBc256206Tahinli5 days ago4000 commits

bench-rows.sh128 lines, 5.5 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# bench-rows.sh: local best-of-5 decode rows (DONE.md D7: speed is measured on the local
3# 12-core machine). Rows: ec-vp8 decode, ec-vp9 decode at 1/2/4/6 tile threads, ec-ac3 5.1
4# 448k decode with parity, ec-h264 decode at 1/2/4/6 cores (the decoder runs 1 thread).
5# Every row starts only when the 1-minute load is below 3; otherwise it waits in 290 s
6# steps for at most 1 h (12 steps). Clips come from scripts/bench-rows-clips.sh.
7# Usage: scripts/bench-rows.sh (prints markdown rows; also saved under $BENCH_CLIPS)
8set -euo pipefail
9root=$(cd "$(dirname "$0")/.." && pwd)
10clips=${BENCH_CLIPS:-$HOME/.cache/benchrows-clips}
11export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-$HOME/.cache/tgt-benchrows}
12export TMPDIR=${TMPDIR:-$HOME/.cache/tmp-benchrows}
13mkdir -p "$TMPDIR"
14rel=$CARGO_TARGET_DIR/release
15today=$(date +%F)
16res="$clips/bench-rows-$today.md"
17: > "$res"
18
19# Prints the 1-minute load once it is below 3. Returns 1 after 1 h of waiting.
20gate() {
21 local steps=0 l
22 while :; do
23 l=$(cut -d' ' -f1 /proc/loadavg)
24 if awk -v l="$l" 'BEGIN { exit !(l < 3) }'; then echo "$l"; return 0; fi
25 if [ "$steps" -ge 12 ]; then echo "$l"; return 1; fi
26 sleep 290
27 steps=$((steps + 1))
28 done
29}
30
31# emit <crate> <clip> <threads> <load> <fps> <realtime> <check>
32emit() {
33 printf '| %s | %s | %s | local 12-core | %s | %s | %s | %s | %s |\n' \
34 "$today" "$1" "$2" "$3" "$4" "$5" "$6" "$7" | tee -a "$res"
35}
36
37# ---- build (outside the gate; nothing is timed here) ----
38cd "$root"
39cargo build --release -q -p ec-vp9 --example decode_ivf
40cargo build --release -q -p ec-ac3 --example ac3dec
41cargo build --release -q --manifest-path tools/ec-bench/Cargo.toml
42cp scripts/bench-rows-vp8.rs crates/ec-vp8/examples/vp8_ivf.rs
43trap 'rm -f "$root/crates/ec-vp8/examples/vp8_ivf.rs"' EXIT
44cargo build --release -q -p ec-vp8 --example vp8_ivf
45
46echo "| date | crate | clip | host | threads | load 1m at start | fps (best of 5) | realtime x | check |"
47echo "|---|---|---|---|---|---|---|---|---|"
48
49# ---- ec-vp8 decode, 1080p30 libvpx clip, 1 thread (the decoder has no thread knob) ----
50vp8=$clips/vp8-1080p30.ivf
51if load=$(gate); then
52 line=$("$rel/examples/vp8_ivf" "$vp8" 5)
53 fps=$(sed -n 's/.*fps=\([0-9.]*\).*/\1/p' <<<"$line")
54 raw=$TMPDIR/vp8.yuv
55 "$rel/examples/vp8_ivf" "$vp8" 1 "$raw" >/dev/null
56 got=$(md5sum "$raw" | cut -d' ' -f1); rm -f "$raw"
57 want=$(cat "$clips/vp8-1080p30.yuv.md5")
58 check="md5 $([ "$got" = "$want" ] && echo "= ffmpeg" || echo "!= ffmpeg ($got)")"
59 emit ec-vp8 "1080p30 libvpx 10 s, 4 Mb/s" 1 "$load" "$fps" "$(awk -v f="$fps" 'BEGIN{printf "%.2fx", f/30}')" "$check"
60else
61 emit ec-vp8 "1080p30 libvpx 10 s" 1 "$load" - - "load gate timed out"
62fi
63
64# ---- ec-vp9 decode, 1080p30 profile 0, 4 tile columns, threads 1/2/4/6 ----
65vp9=$clips/vp9-1080p30-tile4.ivf
66want=$(cat "$clips/vp9-1080p30-tile4.yuv.md5")
67for t in 1 2 4 6; do
68 if load=$(gate); then
69 best=0
70 for _ in 1 2 3 4 5; do
71 f=$("$rel/examples/decode_ivf" "$vp9" "$t" | sed -n 's/.*decode_fps=\([0-9.]*\).*/\1/p')
72 best=$(awk -v a="$best" -v b="$f" 'BEGIN{print (b > a ? b : a)}')
73 done
74 raw=$TMPDIR/vp9.yuv
75 EC_RAW_OUT=$raw "$rel/examples/decode_ivf" "$vp9" "$t" >/dev/null
76 got=$(md5sum "$raw" | cut -d' ' -f1); rm -f "$raw"
77 check="md5 $([ "$got" = "$want" ] && echo "= ffmpeg" || echo "!= ffmpeg ($got)")"
78 emit ec-vp9 "1080p30 profile 0 libvpx-vp9 10 s, 4 tile cols" "$t" "$load" "$best" \
79 "$(awk -v f="$best" 'BEGIN{printf "%.2fx", f/30}')" "$check"
80 else
81 emit ec-vp9 "1080p30 profile 0 tile4" "$t" "$load" - - "load gate timed out"
82 fi
83done
84
85# ---- ec-ac3 decode, AC-3 5.1 448 kb/s, 60 s; speed to /dev/null, parity to a file ----
86ac3=$clips/ac3-5.1-448k.ac3
87if load=$(gate); then
88 best=0
89 for _ in 1 2 3 4 5; do
90 rt=$("$rel/examples/ac3dec" "$ac3" /dev/null | awk -F'\t' '/^realtime/{print $2}')
91 best=$(awk -v a="$best" -v b="$rt" 'BEGIN{print (b > a ? b : a)}')
92 done
93 out=$TMPDIR/ac3.f32
94 errs=$("$rel/examples/ac3dec" "$ac3" "$out" | awk -F'\t' '/^errors/{print $2}')
95 par=$(python3 -I "$root/scripts/bench-rows-parity.py" "$clips/ac3-5.1-448k.ref.f32" "$out" 6 | tail -1)
96 rm -f "$out"
97 emit ec-ac3 "AC-3 5.1 448 kb/s 60 s (5.1 layout)" 1 "$load" "-" "${best}x" \
98 "decode errors $errs; parity: $par"
99else
100 emit ec-ac3 "AC-3 5.1 448 kb/s" 1 "$load" - - "load gate timed out"
101fi
102
103# ---- ec-h264 decode: the bench.log:145 row, from tools/ec-bench itself, pinned to 1/2/4/6
104# cores. The decoder has no thread knob (ec-h264 spawns threads only in enc/), so the
105# core count is the only parallelism available; 5 full ec-bench runs per core count. ----
106bench=$CARGO_TARGET_DIR/release/ec-bench
107for n in 1 2 4 6; do
108 best=""
109 loads=""
110 for _ in 1 2 3 4 5; do
111 if load=$(gate); then
112 line=$(taskset -c "0-$((n - 1))" "$bench" | grep '^| ec-h264 | decode')
113 ms=$(awk -F'|' '{gsub(/ /,"",$6); print $6}' <<<"$line")
114 frames=$(awk -F'|' '{print $4}' <<<"$line" | sed -n 's/.*, \([0-9]*\) frames.*/\1/p')
115 loads="$loads $load"
116 if [ -z "$best" ] || awk -v a="$ms" -v b="$best" 'BEGIN{exit !(a < b)}'; then
117 best=$ms; bestframes=$frames
118 fi
119 else
120 loads="$loads gate-timeout"
121 fi
122 done
123 fps=$(awk -v f="$bestframes" -v m="$best" 'BEGIN{printf "%.2f", f / (m / 1000)}')
124 emit ec-h264 "1080p30 film 10 s, ec-bench row (wall best $best ms, $bestframes frames)" 1 \
125 "$(awk '{print $1}' <<<"${loads# }")" "$fps" "$(awk -v f="$fps" 'BEGIN{printf "%.2fx", f/30}')" \
126 "cores pinned $n, decoder threads 1; loads of 5 runs:$loads"
127done
128echo "saved: $res" >&2