Skip to content

Instantly share code, notes, and snippets.

@terngkub
Last active October 30, 2019 11:19
Show Gist options
  • Select an option

  • Save terngkub/0f07a1295c66add3a5668b57a52d08b0 to your computer and use it in GitHub Desktop.

Select an option

Save terngkub/0f07a1295c66add3a5668b57a52d08b0 to your computer and use it in GitHub Desktop.
push_swap_performance

push_swap_performance

A shellscript to test the performance of push_swap project

About this project

This is the shell script that I wrote to test my push_swap project performance. I also use it to test other people's projects that I review. The script will output:

  • avg = average performance
  • best = performance from the best case
  • worst = performance from the worst case
  • exceed = number of cases that exceed the performance threshold

How to use

  • clone/download the repo
  • move the file "perf.sh" to your push_swap directory (the one that have push_swap execution file)
  • modify the first 3 line of the file and save the file:
    • num = input amount
    • case = number of times that you want to run the test
    • limit = performance threshold (it will use to count the case that have worse performance than this number)
  • run the script
    sh perf.sh
    
num=500
case=100
limit=5300
exceed=0
count=1
sum=0
best=1000000
worst=0
while [ $count -lt $(expr $case + 1) ]
do
arg=$(ruby -e "puts (1..$num).to_a.shuffle.join(' ')")
echo $count
line=$(./push_swap $arg | wc -l)
sum=$(expr $sum + $line)
if [ $line -lt $best ]
then
best=$line
fi
if [ $line -gt $worst ]
then
worst=$line
fi
if [ $line -gt $limit ]
then
exceed=$(expr $exceed + 1)
fi
count=$(expr $count + 1)
done
echo "num : $num"
echo "case : $case"
echo "avg : $(expr $sum / $(expr $count - 1))"
echo "best : $best"
echo "worst : $worst"
echo "exceed: $exceed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment