A faster offset...
A faster offset...
- Subject: A faster offset...
- From: David Lloyd <email@hidden>
- Date: Thu, 06 Sep 2001 17:29:21 +1000
A (much) faster offset...
Today, I was a little surprised by these results, comparing the timings of
the following two snippets, which finds offsets in strings. The first one,
the find offset from the standard additions, took 9 seconds to run, while
the second one, a routine using applescript's text item delimiters, took
only 0.25 seconds to run, which is 36 times faster.
For a script that calls on finding offsets a lot, this turns out to be a bit
of a timesaver. Perhaps it's because it's not needing to call up the osaxen
business? Can anyone confirm that this speed difference is the same for
others?
--snippet 1-----
repeat 500 times
copy (offset of "x" in "asdxasd") to o
end repeat
--snippet 2-----
repeat 500 times
copy offsetInString("x", "asdxasd") to o
end repeat
on offsetInString(theItem, theString)
if theItem "" then
set AppleScript's text item delimiters to theItem
copy (text items of theString) to theItems
set AppleScript's text item delimiters to ""
if (count of theItems) = 1 then
return 0
else
return (length of item 1 of theItems) + 1
end if
else
return 0
end if
end offsetInString
-----
(Not that I'm finding offsets 500 times...)
------
David Lloyd
---------------------------------
email: email@hidden
web:
http://www.kanzu.com
---------------------------------