Created
August 25, 2016 12:34
-
-
Save RobbieClarken/715a582c47d77bbf46b0bbc5c43e07ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
main () { | |
print_runtime > /dev/null | |
print_runtime | |
} | |
print_runtime () { | |
pid=$(start_server) | |
runtime=$(time_command wait_for_server) | |
baseline=$(time_command wait_for_server) | |
echo $runtime - $baseline | bc | |
kill -9 $pid | |
} | |
start_server () { | |
cd example | |
rackup >/dev/null 2>&1 & | |
echo $! | |
} | |
time_command () { | |
local cmd=$* | |
TIMEFORMAT="%3R" | |
(time $cmd) 2>&1 | |
} | |
wait_for_server () { | |
while true; do | |
lsof -i :9292 >/dev/null | |
if [[ $? == 0 ]]; then | |
break | |
fi | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment