Timing a shell script

Rather than an osascript delay, I used the native shell function sleep and ran Kel’s script for 100 iterations:


set lotsa to 0
repeat 100 times
	set t to "import os; import timing; timing.start(); os.popen('sleep 1'); timing.finish(); print timing.milli()"
	set c to "python -c " & quoted form of t
	set lotsa to lotsa + (do shell script c)
end repeat
lotsa / 100 --> 1006.69 msec

According to Hayne (see link later) the discrepancy may be the time it takes to set up the process to do it on MM.

Pretty darn close as you can see! :lol:

Now onward to study Kel’s and Nigel’s later versions, and to consider Cameron Hayne’s post #14 here too. Thanks a lot gentlemen for your interest - I’m converging on understanding just what the overhead of a shell script is.

Later, I’ll compare these two methods of getting seconds since the epoch:


set Aepoch to do shell script "echo 'puts [clock seconds]' | tclsh"

set Pepoch to "python -c 'import time; print time.time(); print time.time()'"
do shell script t