Re: preflighting a file
Re: preflighting a file
- Subject: Re: preflighting a file
- From: Shane Stanley <email@hidden>
- Date: Tue, 19 Feb 2002 16:06:10 +1100
I wrote:
>
> On 19/2/02 6:00 AM +1000, Emmanuel, email@hidden, wrote:
>
>
> Basically, thus:
>
>
>
> ------------------------ untested & unverified
>
> set theFile to open for access alias thePath -- you provide thePath
>
> set theText to read theFile
>
> close access theFile
>
> if offset of "CalGray" in theText is not 0 then
>
> -- do whatever suitable
>
> end
>
> ------------------------
>
>
Except that's going to give you the offset of the first "c" in the file, not
>
"CalGray", without help from third parties.
Which is wrong -- I was confusing "offset of" with "read before".
OTOH, "offset of" is probably the slowest method, at least OMM (AS 1.8.2b1
OS9.2.1). Given a string with the searched-for part in the middle, offset is
quicker for strings of a few characters, "is in" is quicker up to near 1000
characters, and after that TIDs are fastest. On a string of about 4K, TIDs
are nearly twice as fast as "is in", and about 20 times faster than "offset
of". As I said, OMM.
Play with the value of n:
-- build string
set n to 7
set thestring to "helloWorld"
set x to "abcdefghijklmnop"
repeat n times
set x to x & x
end repeat
set x to x & thestring & x
set time1 to the ticks
repeat 500 times
offset of thestring in x
end repeat
set time2 to the ticks
repeat 500 times
thestring is in x
end repeat
set time3 to the ticks
repeat 500 times
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to thestring
count text items of thestring
set AppleScript's text item delimiters to oldDelims
end repeat
set time4 to the ticks
{time2 - time1, time3 - time2, time4 - time3, count of x}
-->>{119, 12, 6, 4106}
(And moving the search string within the string to be searched doesn't make
a great deal of difference).
All of which proves that, for the original poster's needs, any of the three
would work just fine...
--
Shane Stanley, email@hidden
_______________________________________________
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.