Linux runtime

0

I need to take the average run time and CPU de 30 execuções consumption of a program done in Python . I have to use the command time of Linux . Since I've never worked with Linux before I'm having trouble doing this.

This is the code I have made so far (not working). Could someone help me make this work?

size=400
n_cpu=4

/usr/bin/time -f "CPU:  %p    TIME:  %e"
for i in {1..30};
do
    python "script.py" $size $size $n_cpu
done 
    
asked by anonymous 03.06.2015 / 21:15

2 answers

1
python -m timeit -n 30 script.py <…parâmetros…>

timeit is a default Python module, which protects you from all associated pranks with timing Python code (eg when you change the code, Python "recompiles" the code you wrote; this time is discounted by timeit but not by Bash).

    
03.06.2015 / 21:21
1

To get only the time, you can use date

t0=$(date +%s)
for i in {1..5};
do
    sleep 1;
done
tf=$(date +%s)
echo "tempo de execução: $((tf - t0))"

To use the team the way you tried it, you need to loop in a new section of bash with the -c

/usr/bin/time -f "CPU:  %p    TIME:  %e" bash -c "
for i in {1..5};
do
    sleep 1;
done "
    
04.06.2015 / 22:03