Script Execution time check

Hi everyone,

I got the idea to make this from @kel1, he actually wrote the timing script. I just made an app of of it.
you can see his original post here http://macscripter.net/viewtopic.php?pid=40953#p40953.

The script uses python to calculate the time difference between the beginning and the end of whatever AS you enter. It’s possible that it won’t work in every case. I only began writing about 15 minutes ago, but already found a bug. Somehow when you enter “0.0” as script to perform the time check on it will register a negative time.

This script should come in handy when you’re writing a script that performs e.g. lot’s of calculations, downloads files, or anything else that doesn’t involve user interference!

Anyway, without further ado, remember credits mainly go to kel1:


set sc to button returned of (display dialog "To see how fast your script runs; either copy it or open a script." & return & "Please notice that load script times could be off a few seconds." buttons {"Open script.", "Test from clipboard", "Quit"})
if "script" is in sc then
	--set script1 to POSIX path of (
	choose file with prompt "Open a applescript file:" of type {".scpt"}
	testscript_(script1)
else if "Test" is in sc then
	set torun to (do shell script "pbpaste")
	test_(torun)
else
	quit_()
end if
on test_(x)
	repeat 2 times
		set t1 to run script (do shell script "python -c 'import time; print time.time()'")
		set t2 to run script (do shell script "python -c 'import time; print time.time()'")
		set time_calib to t2 - t1
		set t1 to run script (do shell script "python -c 'import time; print time.time()'")
		set x to 1
		-- Enter script here
		x
		
		
		set t2 to run script (do shell script "python -c 'import time; print time.time()'")
		set time_diff to t2 - t1 - time_calib
	end repeat
	if time_diff is less than 0 then
		set sc to button returned of (display dialog "Your script seems to have run in a negative time?" & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	else if time_diff is less than 1 then
		set sc to button returned of (display dialog "Wow, your script seems to be pretty fast!" & return & "Your script ran in " & time_diff & " seconds!" default answer time_diff as text buttons {"Copy to clipboard", "Quit"})
	else if time_diff is less than 3 then
		set sc to button returned of (display dialog "Your script seems to be running pretty normal." & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	else if time_diss is greater than 3 then
		set sc to button returned of (display dialog "Your script is either pretty slow or you have some user interaction in there" & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	end if
	
	ignoring case
		if "copy" is in sc then
			do shell script "echo " & time_diff & "| pbcopy"
		end if
	end ignoring
end test_

on testscript_(x)
	set t1 to run script (do shell script "python -c 'import time; print time.time()'")
	set t2 to run script (do shell script "python -c 'import time; print time.time()'")
	set time_calib to t2 - t1
	set t1 to run script (do shell script "python -c 'import time; print time.time()'")
	set x to 1
	-- Enter script here
	load script x
	
	
	set t2 to run script (do shell script "python -c 'import time; print time.time()'")
	set time_diff to t2 - t1 - time_calib
	
	if time_diff is less than 0 then
		set sc to button returned of (display dialog "Your script seems to have run in a negative time?" & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	else if time_diff is less than 1 then
		set sc to button returned of (display dialog "Wow, your script seems to be pretty fast!" & return & "Your script ran in " & time_diff & " seconds!" default answer time_diff as text buttons {"Copy to clipboard", "Quit"})
	else if time_diff is less than 3 then
		set sc to button returned of (display dialog "Your script seems to be running pretty normal." & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	else if time_diss is greater than 3 then
		set sc to button returned of (display dialog "Your script is either pretty slow or you have some user interaction in there" & return & "It took " & time_diff & " seconds." default answer time_diff as text buttons {"Copy to clipboad", "Quit"})
	end if
	
	ignoring case
		if "copy" is in sc then
			do shell script "echo " & time_diff & "| pbcopy"
		end if
	end ignoring
end testscript_

on quit_()
	log "Quitting"
end quit_

If you have any suggestions or feedback, i’d happily reply!