• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A question on technique
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question on technique


  • Subject: Re: A question on technique
  • From: Thomas Fischer <email@hidden>
  • Date: Tue, 17 Mar 2015 23:41:29 +0100

Hi Shane,

Am 17.03.2015 um 00:03 schrieb Shane Stanley <email@hidden>:

On 17 Mar 2015, at 9:27 am, Thomas Fischer <email@hidden> wrote:

I was playing around with the different suggestions. I tried a list with about 300 entries and 10 KB of text and was looking for entries at the end of the table.
Here it seems that Emmanuel's plist solution is the slowest, the methods checking the items (e.g. Gil's) is about two times as fast.
The methods using the text item delimiters given by Chris again uses only a third of the time and can be slightly accelerating by using the list as a parameter instead of a property, The Satimage find text regular _expression_ search seems to be the fastest with some 10 - 20% less time used.

Am I meant to be hurt that the initial suggestion didn't make the cut?

no, you shouldn't be, but your suggestion started with "If you're running Yosemite, …" and I'm on Mavericks here. So I didn't try anything with your approach.
Thus I couldn't run your script either, I adjusted it for my situation, leaving out ASObjC. For timing I used the OSAX LapTime, I don't know how this compares, but it might intervene somewhat. 

With this I get for 100 rounds results (in milliseconds) like

In Script Editor:
Satimage/regex: 6,76
TIDs: 5,36
Axel's loop: 83,67
Davey's offset: 8,56
TextEdit: 1882,68

As application:
Satimage/regex: 19,89
TIDs: 7,64
Axel's loop: 75,0
Davey's offset: 21,01
TextEdit: 1993,44

The Satimage comes out much slower than when run from AppleScript-Editor, regardless of the warm-up call in the script: it doesn't change significantly when I remove the line
find text "abc" using "\\1" in my lookupTable …
Similarly with Davey's method that uses the Standard Additions OSAX. Is it possible that this is due to the use of the LapTime OSAX?

Best
Thomas


Script:
----------------------
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", "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", "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"}

set iterationCount to (text returned of (display dialog "Number of iterations:" default answer "1")) as integer

-- time Axel's method
set time1 to start timer
repeat iterationCount times
MnemonicOfAxel("9471") -- Axel's version
end repeat
set a to stop timer time1

-- 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 lookupTable to theList as text
set AppleScript's text item delimiters to saveTID

-- time TIDs method
set time1 to start timer
repeat iterationCount times
lookupMnemonic("9471") -- Chris's TIDs handler
end repeat
set z to stop timer time1

-- call Satimage command to force loading, otherwise time is much longer
try
find text "abc" using "\\1" in my lookupTable with regexp and string result without case sensitive
end try

-- time Satimage/regex method
set time1 to start timer
repeat iterationCount times
lookupMnemonicSIO("9471") -- Chris's Satimage handler
end repeat
set y to stop timer time1

-- Davey's Method
set AppleScript's text item delimiters to {tab}
set codesList to (Codes as string) & tab
set time1 to start timer
repeat iterationCount times
MnemonicOfDavey("9471") -- Davey's Offset handler
end repeat
set w to stop timer time1


-- 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 start timer
repeat iterationCount times
MnemonicOfTextEdit("9471") -- TextEdit handler
end repeat
set b to stop timer time1

-- show results
display dialog "Results: " & return & ¬
"Satimage/regex: " & setDecimal(y, 2) & return & ¬
"TIDs: " & setDecimal(z, 2) & return & ¬
"Axel's loop: " & setDecimal(a, 2) & return & ¬
"Davey's offset: " & setDecimal(w, 2) & return & ¬
"TextEdit: " & setDecimal(b, 2)


-- Satimage.osax
on lookupMnemonicSIO(_mnemoic)
try
set _mnemoic to "^" & _mnemoic & "\\t(.+$)"
find text _mnemoic using "\\1" in my 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}}
set _output to paragraph 1 of text item 2 of my 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

on MnemonicOfDavey(aCode)
set k to offset of aCode & tab in my codesList
if k = 0 then return missing value
return item (1 + k div 5) of Mnemonics
end MnemonicOfDavey

on setDecimal(theNumber, theDigits)
set myInteger to round (theNumber * (10 ^ theDigits))
return myInteger / (10 ^ theDigits)
end setDecimal


Mit freundlichen Grüßen
Thomas Fischer

---
Dr. Thomas Fischer
Permosergasse 23a
5026 Salzburg
Tel.: (+43) (0)662 621498
E-Mail: 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

  • Follow-Ups:
    • Re: A question on technique
      • From: Shane Stanley <email@hidden>
    • Re: A question on technique
      • From: Emmanuel LEVY <email@hidden>
References: 
 >A question on technique (From: Gil Dawson <email@hidden>)
 >Re: A question on technique (From: Deivy Petrescu <email@hidden>)
 >Re: A question on technique (From: Deivy Petrescu <email@hidden>)
 >Re: A question on technique (From: "Stockly, Ed" <email@hidden>)
 >Re: A question on technique (From: "Stockly, Ed" <email@hidden>)
 >Re: A question on technique (From: Thomas Fischer <email@hidden>)
 >Re: A question on technique (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Avoiding arbitrary delay functions
  • Next by Date: Re: A question on technique
  • Previous by thread: Re: A question on technique
  • Next by thread: Re: A question on technique
  • Index(es):
    • Date
    • Thread