Re: OS version?
Re: OS version?
- Subject: Re: OS version?
- From: Paul Skinner <email@hidden>
- Date: Fri, 16 May 2003 10:27:01 -0400
On Thursday, May 15, 2003, at 01:39 AM, Emmanuel wrote:
OMM,
--------------------------
do shell script "defaults read | grep SystemVersionStampAsString"
--------------------------
is approximately 3000 times slower than:
--------------------------
system attribute "sysv"
--------------------------
Emmanuel
OK,
For this email...
shellscript is defined as...
<BEGIN SCRIPT>
do shell script "defaults read loginwindow SystemVersionStampAsString"
<END SCRIPT>
sysv is defined as...( John Baltutis posted this version. I believe
it's Apple's example script. )
<BEGIN SCRIPT>
copy my gestVersion_info("sysv", 4) to version_string
version_string
on gestVersion_info(gestalt_code, increment_value)
try
tell application "Finder" to copy my NumToHex((system attribute
gestalt_code), increment_value) to {a, b, c, d}
if a is "0" then set a to ""
set the version_string to (a & b & "." & c & "." & d) as string
return version_string
on error
return "unknown"
end try
end gestVersion_info
on NumToHex(theNumber, stringLength)
set hexString to {}
repeat with i from stringLength to 1 by -1
set hexString to ((theNumber mod 16) as string) & hexString
set theNumber to theNumber div 16
end repeat
return (hexString as string)
end NumToHex
<END SCRIPT>
Both yield the same results.
shellscript wins for code length.
Characters: 64
Spaces: 7
Words: 7
Lines: 1
vs. sysv's...
Characters: 551
Spaces: 125
Words: 102
Lines: 22
sysv wins for speed.
Speed comparison:
During this test there were 17 other processes competing for the
processor's attention.
1 Data sets were used.
100 executions per data set were averaged.
shellscript
0.03696 seconds average duration.
3.696 seconds total time for 100 executions.
4.999999999997E-5 seconds delta from last run.
sysv
0.00469 seconds average duration.
0.469 seconds total time for 100 executions.
3.0E-5 seconds delta from last run.
SUMMARY
sysv was faster by...
0.03227 seconds.
688 %
6.880597014925 X
Conclusion:
If you can type sixty words per minute and you make no errors and code
it perfectly the very first time then the sysv version takes you 1.583
seconds longer to type than the Shell script version. *
If you run the sysv version 50 times on the same machine then you will
have saved yourself some time.
Observation:
If you get the OS version ,via script, enough in any script to see the
speed difference between these two methods then you have bigger coding
problems than choosing the faster method can help. : )
*You may note that this is an extremely optimistic value. You may also
suggest copy and paste as an alternative to typing. Try it and time
yourself. You may also note that this post is FULL of sarcasm.
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.