In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (John Delacour) 
wrote:

> I did a test using osacompile and osascript.  The fastest result 
> comes from using osascript with a precompiled AS script.

As one would expect.  Good.  I'd be shocked if it were otherwise.

> This takes 
> 0.8 seconds.  If I use  -e and the script text, it takes about 1.5 
> seconds.

I get this on my PowerBook G4:

  $ time osascript -e 'tell application "Finder" to activate'
  real    0m0.635s
  user    0m0.200s
  sys     0m0.150s

  $ time perl -MMac::Glue -e 'Mac::Glue->new("Finder")->activate'
  real    0m1.733s
  user    0m1.160s
  sys     0m0.150s

  $ time osascript -e 'tell application "Finder" to get name of window 1'
  pudge
  real    0m0.447s
  user    0m0.200s
  sys     0m0.100s

  $ time perl -MMac::Glue -e 'print Mac::Glue->new("Finder")->prop(name => 
  window => 1)->get'
  pudge
  real    0m1.599s
  user    0m1.210s
  sys     0m0.170s


The AppleScript version is certainly lighter weight than the equivalent Perl 
script, in part because the Perl script takes a lot more to compile, there's 
a lot more Perl code to compile in the modules, and there's the dynamic 
libraries to load in.

The Mac::Glue version doesn't need to "ping" the Finder to get its aete like 
the AppleScript version does, but that very well may be a wash, as Mac::Glue 
needs to read in the aete from the glue file on disk.

When you do multiple iterations, the increase is tiny.  If I add a 'for 
0..10' to the window name Perl script:

  real    0m1.778s
  user    0m1.290s
  sys     0m0.190s

Which goes toward what I am about to post to the MACSCRPT list about how 
Perl can be quite efficient, if you can find a way to preload the libraries 
(maybe with a daemon) and precompile the script, like in X-Chat, where 
execution is virtually immediate, because the perl library is loaded in, and 
the script is cached in memory.

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to