Re: Mac:: speed (was: Getting a 'Save As' dialog box)

2004-01-12 Thread John Delacour
At 10:55 am -0800 12/1/04, Chris Nandor wrote:

The script I just posted took 3.263 seconds, including hitting Cancel to
make the dialog box go away, on a PowerBook G4/867 running Panther.  Total
user/sys time was 1.39 seconds.  Pain is highly dependent on your system
specifics and pain threshhold.
I have exactly the same set-up.  The only difference seems to be my 
pain threshold :-)

In my experience, Panther is quite a bit faster with Mac::Carbon startup
than Jaguar was.  I've got some benchmarks I keep meaning to clean up and
post.  The time spent in dyld has -- the biggest problem -- has been
dramatically reduced.
The problem with your routine is that you need to display the dialog 
in a process which a) has glue available and b) the user does not 
want to activate.

Besides that, the user is required to learn a new way of expressing 
the terminology rather than simply using the familiar AppleScript way.

The routine using Mac::AppleScript seems so much simpler to me and it 
is possible to display dialogs without leaving the current 
application, whether it be Terminal or the editor (at least the one 
I'm using).  RunAppleScript requires the learning of one simple 
command, allows the scripts to be easily debugged in an AppleScript 
editor and simply pasted into the Perl script. As to speed, I have 
done no precise timings.  Neither method is fast and 3 seconds to me 
is an awful long time if you think what that might have taken on a 66 
MHz machine.  I don't pretend to understand the low-level stuff, but 
I know Panther does a lot of basic things more slowly than a Mac Plus.

use Mac::AppleScript qw(RunAppleScript);
$asresult = RunAppleScript AS;
tell app Terminal
  display dialog Enter a number: default answer 55
  text returned of result as real
end
AS
print $asresult**2 . $/;



Re: Mac:: speed (was: Getting a 'Save As' dialog box)

2004-01-12 Thread Chris Nandor
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (John Delacour) 
wrote:

 I have exactly the same set-up.  The only difference seems to be my 
 pain threshold :-)

Yes, that whole extra second Mac::Glue takes over osascript can be annoying.  
I am only being half-facetious, I know it can be, depending on the context.  
But in most cases, it won't be significant.

You may not be aware, but unlike RunAppleScript(), the worst overhead 
involved with Mac::Glue is on script startup only, whereas with 
RunAppleScript() there will be slowness overhead associated with every call 
to the function.

[As a side note: again noting that the delay is entirely in the startup, I 
use Mac::Glue a lot in XChat scripts, and they are loaded in once and cached 
a la mod_perl, so there is no startup issue.  You get immediate results, 
just as one would expect from a compiled AppleScript.]


 The problem with your routine is that you need to display the dialog 
 in a process which a) has glue available and b) the user does not 
 want to activate.

I don't understand the complaint.  It's just like yours.  Yes, you need a 
glue, but that's a one-time operation (% glue /Applications/Terminal); 
it's not a big deal.  And yours targets the application too; what's the 
difference?


 Besides that, the user is required to learn a new way of expressing 
 the terminology rather than simply using the familiar AppleScript way.

You are assuming people on this list are familiar with AppleScript.  I make 
no such (false) assumption.  :)


 The routine using Mac::AppleScript seems so much simpler to me

Yes, of this I have no doubt.

 and it is possible to display dialogs without leaving the current 
 application, whether it be Terminal or the editor (at least the one 
 I'm using).

OK, I think you misunderstood.  It works just fine using any app as the 
target app, as long as it is scriptable, just like yours.


 done no precise timings.  Neither method is fast and 3 seconds to me 
 is an awful long time if you think what that might have taken on a 66 
 MHz machine.

Three seconds *including clicking Cancel*.  So it relies on silly user 
interaction, hence the note of the user/sys CPU times.  Here's a quick 
similarly dumb benchmark that relies on user interaction:


[EMAIL PROTECTED] pudge]$ time osascript -e 'tell app Terminal to choose file 
name with prompt test1 default name test2'
real0m1.136s
user0m0.200s
sys 0m0.070s

[EMAIL PROTECTED] pudge]$ time perl -MMac::Glue -e 'my $glue = new Mac::Glue 
Terminal; $glue-choose_file_name(with_prompt = test1, default_name = 
test2);'
real0m2.398s
user0m1.120s
sys 0m0.210s

Woohoo, I clicked Cancel faster on that run.  :)  The real number is 0.27 
vs. 1.33 there.  About a second difference.


 use Mac::AppleScript qw(RunAppleScript);
 $asresult = RunAppleScript AS;
 tell app Terminal
display dialog Enter a number: default answer 55
text returned of result as real
 end
 AS
 print $asresult**2 . $/;

use Mac::Glue;
my $glue = new Mac::Glue 'Terminal';
my $result = $glue-display_dialog('Enter a number:', default_answer = 55);
print $result-{text_returned}**2, \n;

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