Adds a profiler to help enhancing problem solving

This commit is contained in:
Julien Lengrand-Lambert
2012-02-15 15:45:27 +01:00
parent ebc41b633a
commit f16f45ce7b
2 changed files with 7 additions and 41 deletions

7
euler_profiler Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
# Used to easily profile a solution to Project Euler
PROBLEM=$1
python -m cProfile -s time $PROBLEM

View File

@@ -1,41 +0,0 @@
#!/bin/bash
# Brrr this is ugly. You 'd better change it quickly
TYPE=$1
FILE="e_$1.py"
if [ $# -gt 1 -o $# -lt 1 ];
then
echo "Main usage is : euler_template number_of_problem"
exit 0;
fi
#generating shellbang
#echo -e "#!"$(which $TYPE)"\n" >> $FILE
echo "#!/usr/bin/env python " >>$FILE
#generating header
echo -e '"""' >> $FILE
echo -e " ##---" >> $FILE
echo -e " # Julien Lengrand-Lambert" >> $FILE
echo -e " #Created on : "$(date)"\n #" >> $FILE
echo -e " # DESCRIPTION : Solves problem $1 of Project Euler" >> $FILE
echo -e ' ' >> $FILE
echo -e " ##---" >> $FILE
echo -e '"""' >> $FILE
# function prototype
echo -e 'def fun():' >> $FILE
echo -e ' """' >> $FILE
echo -e ' """' >> $FILE
echo -e ' ' >> $FILE
echo -e ' return 1' >> $FILE
echo -e '' >> $FILE
# main
echo -e "if __name__ == '__main__':" >> $FILE
echo -e ' print "Answer : %d" % (fun())' >> $FILE
chmod +x $FILE