• 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: Emmanuel LEVY <email@hidden>
  • Date: Wed, 18 Mar 2015 00:06:11 +0100

Hi,

Maybe interesting, the plist method is faster than any on my machine.

(Not a surprise for me, plists were designed exactly for that kind of job).

Thanks to Thomas it took a pair of seconds to me to write the test, here are the results I got for 10000 iterations, and the script is below, I just brought small changes to Thomas' script.

Best,
Emmanuel

Results:
Satimage/regex: 1.064
TIDs: 0.862
Axel's loop: 18.852
Davey's offset: 1.233
Plist: 0.438

---------------
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", "ED
M", "RfW", "ENM", "ReW", "EOC", "EDM", "RfW", "ENM", "ReW", "EOC", "RfX"}
property p : ""

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

-- 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

on lookupPlist(_mnemoic)
	PlistGet p key _mnemoic
end lookupPlist

-- 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

-- time Axel's method
chrono
repeat iterationCount times
	MnemonicOfAxel("9471") -- Axel's version
end repeat
set a to chrono

-- 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
chrono
repeat iterationCount times
	lookupMnemonic("9471") -- Chris's TIDs handler
end repeat
set z to chrono

-- 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
chrono
repeat iterationCount times
	lookupMnemonicSIO("9471") -- Chris's Satimage handler
end repeat
set y to chrono

-- create plist
set p to PlistNew
PlistSet p key Codes to Mnemonics

-- time Plist method
chrono
repeat iterationCount times
	lookupPlist("9471")
end repeat
set c to chrono

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

(*
-- 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 & (printf "Satimage/regex: %.3f" & return & "TIDs: %.3f" & return & "Axel's loop: %.3f" & return & "Davey's offset: %.3f" & return & "Plist: %.3f" parameters {y, z, a, w, c})

(printf "Satimage/regex: %.3f" & return & "TIDs: %.3f" & return & "Axel's loop: %.3f" & return & "Davey's offset: %.3f" & return & "Plist: %.3f" parameters {y, z, a, w, c})

------------------------------



 _______________________________________________
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: Thomas Fischer <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>)
 >Re: A question on technique (From: Thomas Fischer <email@hidden>)

  • Prev by Date: Re: A question on technique
  • 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