Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created August 12, 2014 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacobsalmela/88a252e84a099f4688af to your computer and use it in GitHub Desktop.
Save jacobsalmela/88a252e84a099f4688af to your computer and use it in GitHub Desktop.
Script performance test
#!/bin/bash
#----------AUTHOR------------
# Jacob Salmela
# 27 March 2014
# https://github.com/jakesalmela/
#---------DESCRIPTION--------
# Tests the performance of a script
#-----------USAGE------------
# To run:
#
# ./script-performance-test.sh <yourScriptAsAnArgument.sh>
#
#----------VARIABLES---------
# $1 will be the script to test
# It should be passed as an argument to this script
#----------FUNCTIONS---------
function performanceTest()
{
# Run this loop 10 times
for i in {1..10}
do
# Time the script (argument passed to this script) sending the output into the Sarlaac Pit
time $1 >/dev/null
# awk out only the last field, which is the time it took to run the script each time
done 2>&1 | awk '/real/ {print $2}'
}
#---------------------------------#
#----------BEGIN SCRIPT-----------#
#---------------------------------#
performanceTest $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment