Last active
August 30, 2023 08:32
-
-
Save grubernd/48aaf1c1ed087f6d41eedb794a03b7ee to your computer and use it in GitHub Desktop.
ImagesPerHour - benchmark darktable conveniently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# ----------------------------------------------------------------------------- | |
# ## iph | |
# | |
# > GRUBERND 2023 <http://grubernd.at> :: MIT License | |
# | |
# _Revision 2023-08-30_ | |
# | |
# ----------------------------------------------------------------------------- | |
# Benchmarking (darktable) image processing for custom usages | |
# | |
# + IPH = Images Per Hour | |
# + 23.08 initial version | |
# | |
# ----------------------------------------------------------------------------- | |
_iph_version="23.08" | |
output_folder="/tmp/iph-output" | |
darktable_extra_args="$@" | |
folders=$(find . -maxdepth 1 -type d -iname "set*" |sed 's/\.\///' |sort) | |
# ----------------------------------------------------------------------------- | |
_iph_help () { | |
cat << HELPEND | |
Arguments: | |
- All arguments are passed directly to the darktable-cli. | |
Both native and --core parameters can be used. | |
Dependencies: | |
- darktable-cli .. for obvious reasons | |
- Python3 .. for correct floating point math and rounding | |
Datastructure: | |
./set-a/ # folder with images | |
./set-a.xmp # tool settings used to process the images | |
... | |
The fineprint: | |
- Folders MUST start with 'set' to be found | |
- Darktable settings xmp MUST match the folder name plus extension ".xmp" | |
- No whitespace allowed in names of folders or setting files | |
- Calculations depend on correct counting of files: | |
- Image files MUST be bigger than 1M | |
- All other files inside the sets MUST be smaller than 1M | |
- All messages from darktable-cli get /dev/null'ed | |
HELPEND | |
} | |
# ----------------------------------------------------------------------------- | |
_iph () { | |
# iph == Images Per Hour | |
# | |
# Do not use bc or awk to calculate this, | |
# they have problems with floating point math and rounding values. | |
millis_elapsed="$1" | |
images_processed="$2" | |
echo "print(round(float(3600000 / $millis_elapsed * $images_processed)))" |python3 | |
} | |
# ----------------------------------------------------------------------------- | |
echo "iph $_iph_version GRUBERND" | |
echo "Benchmarking images per hour" | |
date -Iseconds | |
echo "" | |
# ----------------------------------------------------------------------------- | |
if [ $(which darktable-cli) == "" ]; then | |
_iph_help | |
echo "Error. Dependency not installed" | |
darktable-cli | |
exit 1 | |
fi | |
if [ $(which python3) == "" ]; then | |
_iph_help | |
echo "Error. Dependency not installed" | |
python3 | |
exit 1 | |
fi | |
if [ -z "$folders" ]; then | |
_iph_help | |
echo "Error. No folders starting with 'set' found" | |
exit 2 | |
fi | |
for d in $folders; do | |
if [ ! -f "$d.xmp" ]; then | |
_iph_help | |
echo "Error. Darktable sidecar not found: $d.xmp" | |
exit 4 | |
fi | |
done | |
if [ ! -d "$output_folder" ]; then | |
mkdir -v "$output_folder" | |
if [ ! -d "$output_folder" ]; then | |
echo "Could not create folder for output: $output_folder" | |
exit 7 | |
fi | |
fi | |
echo "Prerequisites ok" | |
if [ $(_iph 40179 10) != 896 ]; then | |
echo "Test failed: _iph calculation" | |
exit 9 | |
fi | |
# ----------------------------------------------------------------------------- | |
darktable-cli --version |head -1 | |
echo "Running on $(hostname)" | |
echo "" | |
result_sum=0 | |
test_count=0 | |
for d in $folders; do | |
image_count=$(find $d/ -type f -size +1M |wc -l) | |
timer_start=$(( $(date +%s%N) / 1000000 )) | |
darktable-cli $d/ $d.xmp "$output_folder"/ $darktable_extra_args &>/dev/null | |
timer_stop=$(( $(date +%s%N) / 1000000 )) | |
milliseconds_elapsed=$(( timer_stop - timer_start )) | |
this_result=$(_iph $milliseconds_elapsed $image_count) | |
result_sum=$(( result_sum + this_result )) | |
test_count=$(( test_count + 1 )) | |
echo -e "$this_result\tIPH\t$d" | |
done | |
echo "" | |
echo -e "$(( result_sum / test_count ))\tIPH-AVERAGE" | |
echo "" | |
echo -e "$result_sum\tIPH-SUM" | |
# ----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment