Skip to content

Instantly share code, notes, and snippets.

@wilhuff
Last active September 3, 2019 16:06
Show Gist options
  • Save wilhuff/8e4635f14dff5cc7e2732c693448875c to your computer and use it in GitHub Desktop.
Save wilhuff/8e4635f14dff5cc7e2732c693448875c to your computer and use it in GitHub Desktop.
benchmark builds
#!/bin/bash
function find_sources() {
find Firestore/Source Firestore/Example/Tests Firestore/core \( \
-name \*.m -o -name \*.cc -o -name \*.mm \
\) -print
}
function find_object_names() {
find_sources | sed 's,.*/,,; s/\.[^\.]*$/.o/'
}
function find_object_find_args() {
find_object_names | sed '
1 s/^/-name /;
2,$ s/^/-o -name /;
'
}
function find_objects() {
find ~/Library/Developer/Xcode/DerivedData \( $(find_object_find_args) \) -print
}
function clean_firestore() {
find_objects | xargs rm
}
function clean_all() {
rm -rf ~/Library/Developer/Xcode/DerivedData
}
function build() {
xcodebuild \
-workspace Firestore/Example/Firestore.xcworkspace \
-scheme Firestore_IntegrationTests_iOS \
-sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7' \
ONLY_ACTIVE_ARCH=YES CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=YES \
COMPILER_INDEX_STORE_ENABLE=NO \
build 2>&1 | xcpretty 1>&2
}
function time_now() {
gdate -u '+%s.%N'
}
function float_add() {
bc <<< "$1 + $2"
}
function float_sub() {
bc <<< "$1 - $2"
}
function timed_build() {
start=$(time_now)
build
end=$(time_now)
float_sub $end $start
}
function benchmark_all() {
clean_all
timed_build
}
function benchmark_full_firestore() {
clean_firestore
timed_build
}
function benchmark_incremental() {
touch Firestore/core/src/firebase/firestore/util/status.h
timed_build
}
benchmark=benchmark_all
iterations=10
results=()
total=0.0
echo "Warming up ..."
# warmup
$benchmark
echo "Running $iterations iterations ..."
for ((i=0; i<$iterations; i++)); do
duration=$($benchmark)
results+=($duration)
total=$(float_add $total $duration)
echo "$duration"
done
mean=$(bc <<< "scale = 4; $total / $iterations")
echo
echo "Results"
for result in "${results[@]}"; do
echo $result
done
echo
echo "Total: $total"
echo "Count: $iterations"
echo "Mean: $mean"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment