Re: A question on technique
Re: A question on technique
- Subject: Re: A question on technique
- From: Deivy Petrescu <email@hidden>
- Date: Tue, 17 Mar 2015 14:14:45 -0400
I run this script with 100 iterations got this result:
Results:
ASObjC: 5.083978176117
Satimage/regex: 1646.08299732208
TIDs: 9.573996067047
Axel's loop: 49.050986766815
TextEdit: 463.517010211945
According to you this is in milliseconds.
I run this script using your Codes and Mnemonics.
<script>
tid(space)
set TMnemonics to Mnemonics as string
set t to (current date)
repeat 100000 times
set k to round (offset of "RfX" in TMnemonics) / 4 rounding up
end repeat
return ((current date) - t) / 1000
on tid(x)
set AppleScript's text item delimiters to x
end tid
</script>
—> 0.07 also in milliseconds.
> On Mar 16, 2015, at 23:18 , Shane Stanley <email@hidden> wrote:
>
> On 17 Mar 2015, at 1:23 pm, Olof Hellman <email@hidden> wrote:
>>
>> And here’s a third, using TextEdit app (fairly universally available) as your search engine. This will scale well for performance
>
> It might scale well, but it's still much, much slower.
>
> Here's a script that times several of the methods posted. It uses a list of 300 items, with only the last one matching. It requires Yosemite for the ASObjC version and timing, and it should be run as an applet, because editors skew results (as, probably, does using a large number of iterations). Results are in milliseconds.
>
> The first thing you'll see is that results vary. But typically the osax/regex method is fastest, followed closely by the ASObjC and TIDs methods. Looping through is slower, and calling in an app like TextEdit blows out the times massively.
>
> use AppleScript version "2.4" -- requires 10.10
> use scripting additions -- requires Satimage.osax
> use framework "Foundation"
>
> property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "942C", "9470", "94a
e", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "9470", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "942C", "9470", "94ae", "94d0", "942f", "9471"}
> property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "
EDM", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "RfX"}
> property codesAndMnemonics : missing value -- will hold dictionary
> property lookupTable : "" -- will hold string for later methods
>
> set iterationCount to (text returned of (display dialog "Number of iterations:" default answer "1")) as integer
>
> -- create dictionary
> set my codesAndMnemonics to current application's NSDictionary's dictionaryWithObjects:Mnemonics forKeys:Codes
>
> -- time ASObjC method
> set time1 to current application's NSDate's |date|()
> repeat iterationCount times
> MnemonicOf("9471") -- ASObjC handler
> end repeat
> set x to ((time1's timeIntervalSinceNow()) * -1000)
>
> -- time Axel's method
> set time1 to current application's NSDate's |date|()
> repeat iterationCount times
> MnemonicOfAxel("9471") -- Axel's version
> end repeat
> set a to ((time1's timeIntervalSinceNow()) * -1000)
>
> -- create tab/return-delimited string for Chris's methods
> set theList to {}
> repeat with i from 1 to count of Codes
> set end of theList to item i of Codes & tab & item i of Mnemonics
> end repeat
> set saveTID to AppleScript's text item delimiters
> set AppleScript's text item delimiters to {return}
> set my lookupTable to theList as text
> set AppleScript's text item delimiters to saveTID
>
> -- time TIDs method
> set time1 to current application's NSDate's |date|()
> repeat iterationCount times
> lookupMnemonic("9471") -- Chris's TIDs handler
> end repeat
> set z to ((time1's timeIntervalSinceNow()) * -1000)
>
> -- call Satimage command to force loading, otherwise time is much longer
> try
> find text "abc" using "\\1" in lookupTable with regexp and string result without case sensitive
> end try
>
> -- time Satimage/regex method
> set time1 to current application's NSDate's |date|()
> repeat iterationCount times
> lookupMnemonicSIO("9471") -- Chris's Satimage handler
> end repeat
> set y to ((time1's timeIntervalSinceNow()) * -1000)
>
> -- build TextEdit doc for Olof's method
> set allMnemonics to ""
> repeat with n from 1 to count Codes
> set allMnemonics to allMnemonics & item n of Codes & ", " & item n of Mnemonics & return
> end repeat
> tell application "TextEdit"
> if not (exists document "Mnemonics") then
> make new document with properties {name:"Mnemonics"}
> end if
> set text of document "Mnemonics" to allMnemonics
> end tell
>
> -- time TextEdit doc method
> set time1 to current application's NSDate's |date|()
> repeat iterationCount times
> MnemonicOfTextEdit("9471") -- TextEdit handler
> end repeat
> set b to ((time1's timeIntervalSinceNow()) * -1000)
>
> -- show results
> display dialog "Results: " & return & "ASObjC: " & x & return & "Satimage/regex: " & y & return & "TIDs: " & z & return & "Axel's loop: " & a & return & "TextEdit: " & b
>
> on MnemonicOf(aCode)
> set returnResult to codesAndMnemonics's objectForKey:aCode
> if returnResult = missing value then
> -- whatever
> return false
> else
> return returnResult as text
> end if
> end MnemonicOf
>
> -- Satimage.osax
> on lookupMnemonicSIO(_mnemoic)
> try
> set _mnemoic to "^" & _mnemoic & "\\t(.+$)"
> find text _mnemoic using "\\1" in lookupTable with regexp and string result without case sensitive
> on error
> return false
> end try
> end lookupMnemonicSIO
>
> -- use TIDs
> on lookupMnemonic(_mnemoic)
> set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {_mnemoic & tab}}
> text items of lookupTable
> set _output to paragraph 1 of text item 2 of lookupTable
> set AppleScript's text item delimiters to oldTIDS
> return _output
> end lookupMnemonic
>
> on MnemonicOfAxel(aCode)
> local k
> repeat with k from 1 to length of my Codes
> if item k of my Codes is aCode then return item k of my Mnemonics
> end repeat
> return missing value
> end MnemonicOfAxel
>
> on MnemonicOfTextEdit(aCode)
> tell application "TextEdit"
> set theParagraphs to every paragraph of document "Mnemonics" where it begins with aCode
> end tell
> return ((characters 7 thru -2 of item 1 of theParagraphs) as text)
> end MnemonicOfTextEdit
>
>
> --
> Shane Stanley <email@hidden>
> <www.macosxautomation.com/applescript/apps/>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
Deivy Petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden