My laptop spent 1.3 seconds to complete the process posted below. The same code ran on another machine and the timing was different: 2.1 seconds. This is because another machine runs on different Operation System, it has different CPU, memory and etc.
I wonder if instead of timing the process in seconds there would be a way to measure CPU cycles it took for the computer to complete a given process. So if the same code is run on different machines the measurements taken would always result the same number, and the result would be something like: it took 10,000 CPU cycles for this process to complete
….
JavaScript
x
8
1
import time
2
def run():
3
for i in range(10000000):
4
0+0
5
start_time = time.time()
6
run()
7
print 'processed in: %s sec'%(time.time() - start_time)
8
Advertisement
Answer
on linux systems you have time
command, ie:
JavaScript
1
3
1
# time ls
2
/bin/ls ${=LS_OPTIONS} 0.00s user 0.00s system 68% cpu 0.003 total
3