At 1:01 am -0800 13/1/04, Chris Nandor wrote:


The second is Mac OS X 10.3.2.

  $ time perl -MMac::Glue -e 'Mac::Glue->new("Finder")->activate'
  real    0m2.067s
  user    0m1.430s
  sys     0m0.320s

  $ time perl -MMac::Carbon -e1
  real    0m1.300s
  user    0m1.130s
  sys     0m0.140s

Wow.  That's pretty dramatic.  More than 10x faster in real, and about 5x
faster in user+sys.  Why the speedup?


I did a test using osacompile and osascript. The fastest result comes from using osascript with a precompiled AS script. This takes 0.8 seconds. If I use -e and the script text, it takes about 1.5 seconds. It takes over 2 seconds if I first osacompile the script and then use osascript to run the script in two stages. Anyone interested in trying this can comment out the osacompile line or one of the $run lines or and/or move the timer.



use Time::HiRes qw(gettimeofday) ;
chdir "/tmp" ;
$ae_end = "------oo  end of event  oo------\n";
$compiled_as = "temp.scpt";
open F, ">$compiled_as" ; # create the file
close F;
$script_text = <<AppleScript_Code
            tell app "Finder" to get name of window 1
AppleScript_Code
# compile the code into temp.scpt
`osacompile -e '$script_text' -o $compiled_as` ;
# run the compiled script -- about 0.8 seconds
$run = `osascript '$compiled_as'` ;
$t = gettimeofday(); ### <=====<
# compile the code and run all in one go -- about 1.5 seconds
$run = `osascript -e '$script_text'` ;
$t1 = gettimeofday() - $t ; ### <=====<
@bits = split $ae_end, $run ;
chomp ($result = $bits[-1]) ;
print "$result      $t1\n" ;



Reply via email to