Skip to content

Instantly share code, notes, and snippets.

@antonlacon
Last active September 8, 2018 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonlacon/9c36c0eb40c8e6ba6ba408e97d0a79cc to your computer and use it in GitHub Desktop.
Save antonlacon/9c36c0eb40c8e6ba6ba408e97d0a79cc to your computer and use it in GitHub Desktop.
(De)Compress a file repeatedly to benchmark zlib by way of mini(un)zip
#!/bin/sh
#
# Benchmark zlib performance using programs available to LibreELEC.
#
# Number of iterations to loop
COMPRESS_ITER=50
DECOMPRESS_ITER=50
# test file to compress & then decompress
CORPUS="/storage/zlib-test/Gutenberg-Mark-Twain.html"
CORPUS_FILE=$(basename "${CORPUS}")
TEMP_DIR=$(mktemp -d)
# Compression testing
for i in $(seq 0 $COMPRESS_ITER); do
# Copy corpus to tmpfs
cp "${CORPUS}" "${TEMP_DIR}/${CORPUS_FILE}"
# Use first run to create zip file for decompression
if [ $i = 0 ]; then
# Note: minzip overwrites without confirmation
/storage/zlib-test/minizip "${TEMP_DIR}/corpus.zip" "${TEMP_DIR}/${CORPUS_FILE}"
else
# Dump output to /dev/null to minimize I/O issues
time -a -o "${TEMP_DIR}/compress_time.txt" \
/storage/zlib-test/minizip -o /dev/null "${TEMP_DIR}/${CORPUS_FILE}"
fi
done
# Clean up the time output
grep "real" "${TEMP_DIR}/compress_time.txt" | cut -f 2 | tr -d ' ' \
> "${TEMP_DIR}/compress_real.txt"
# Decompression testing
for i in $(seq 0 $DECOMPRESS_ITER); do
if [ $i = 0 ]; then
/storage/zlib-test/miniunz "${TEMP_DIR}/corpus.zip" -o -d "${TEMP_DIR}"
# Dump unzipped contents to tmpfs to minimize I/O issues (/dev/null unavail to miniunz)
else
time -a -o "${TEMP_DIR}/decompress_time.txt" \
/storage/zlib-test/miniunz "${TEMP_DIR}/corpus.zip" -o -d "${TEMP_DIR}"
fi
done
# Clean up the time output
grep "real" "${TEMP_DIR}/decompress_time.txt" | cut -f 2 | tr -d ' ' \
> "${TEMP_DIR}/decompress_real.txt"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment