Skip to content

Instantly share code, notes, and snippets.

@daanpeer
Last active March 5, 2018 21:07
Show Gist options
  • Save daanpeer/2da8e5fb8bded8fcd6c48db0e92003c3 to your computer and use it in GitHub Desktop.
Save daanpeer/2da8e5fb8bded8fcd6c48db0e92003c3 to your computer and use it in GitHub Desktop.
Docker benchmark
#!/bin/bash
# The path to write results to
benchmark_dir='./benchmarkResults/';
# use this to check the final results
result_filename='results.txt';
# Use this to tail the progress of the containers
output_filename='output.txt';
# The command to run in the container
docker_command='listo npm run jest';
# The amount of iterations to run
iteration_count=10;
result_path=$benchmark_dir$result_filename;
output_path=$benchmark_dir$output_filename;
function clean_containers() {
echo "Cleaning containers!";
docker stop $(docker ps -a -q);
docker rm $(docker ps -a -q);
docker volume prune -f;
echo "Cleaning complete!";
}
function run_test_part() {
echo "Running command \"$1\" $iteration_count times";
for (( i=1; i<=$iteration_count; i++ ))
do
start=`date +%s`;
eval $2;
end=`date +%s`;
echo "#$i $1 \n" >> $result_path;
result=$((end-start));
echo $result >> $result_path;
echo "Iteration $i of test $1 completed in $result seconds";
clean_containers;
done;
}
echo 'Cleaning old results';
rm -rf $benchmark_dir;
echo "Making result dir $benchmark_dir";
mkdir $benchmark_dir;
echo 'Cleaning containers and volumes';
clean_containers;
echo 'Going to start running commands';
# Change these to your own commands
run_test_part "Native" "docker-compose run $docker_command >> $output_path";
run_test_part "Cached" "docker-compose -f docker-compose-cached.yml run $docker_command >> $output_path";
run_test_part "Docker sync unison" "docker-sync start && docker-compose -f docker-compose-sync.yml run $docker_command >> $output_path";
run_test_part "Docker sync native_osx" "docker-sync start --config docker-sync-osx.yml && docker-compose -f docker-compose-sync.yml run $docker_command >> $output_path";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment