Re: Optimize your script with Shark
Re: Optimize your script with Shark
- Subject: Re: Optimize your script with Shark
- From: has <email@hidden>
- Date: Tue, 18 Oct 2005 01:24:48 +0100
Daniel Jalkut wrote:
>For the more technically inclined, you might be interested in a technique I'm playing with for invoking Shark from within an AppleScript:
>
>http://www.red-sweater.com/blog/?p=41
>It can be interesting for comparing the efficiency of various approaches.
That's not really what profilers are about. For comparing individual algorithms as your example does, it's a lot simpler to use a timing osax like GetMilliSec and wrap the code to test in something like the following:
set n to 1000 -- no of times to run each test
set t to GetMilliSec
repeat n times
-- [algorithm 1 goes here]
end repeat
set t1 to (GetMilliSec) - t
set t to GetMilliSec
repeat n times
-- [algorithm 2 goes here]
end repeat
set t2 to (GetMilliSec) - t
log {t1, t2}
You'll have to [where appropriate] run the tests over a representative range of test data to see how each algorithm holds up under different loads, and you'll also need to understand things like big-O calculations and the difference between speed and efficiency to make sense of the results.
Where profilers are useful is in running whole-program analyses to see which *subroutines* your program spends the most of its time in. The idea is you use the profiler to quickly and easily identify the three or four routines where the program spends the majority of its time, so that you know which parts of your program to selectively optimise in order to get the biggest performance improvement for the minimum amount of work. For AppleScripters, that means measuring the time spent in each AS handler - you don't need or want to see the details of anything else (i.e. machine-level calls occurring within the AS interpreter, the host app or any remote apps called from the script). I've not used Shark myself, but would be a little surprised if it could provide that sort of information since interpreter-level calls operate on a different level to machine-level calls. (Though if you can find a way to do it, do tell...)
I do agree that a profiler for AS would be a nice thing to have (assuming the user has the programming skills to use it productively), but it's really something that needs to hook directly into the AS interpreter itself, which means Apple would have to provide it. (i.e. Don't hold your breath.) Of course, you can profile AS code with nothing but a timing osax and a bit of manual work if/when you really have to; it's just more convenient with an automated tool if you have one.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden