• 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
Speed of long lists (was: Importing/parsing CSV files)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Speed of long lists (was: Importing/parsing CSV files)


  • Subject: Speed of long lists (was: Importing/parsing CSV files)
  • From: T&B <email@hidden>
  • Date: Sat, 16 Sep 2006 14:18:55 +1000

Following up my earlier script (the contents of which I never actually posted):

I wrote my own new script that uses AppleScript's text item delimiters to do the work. Basically, it replaces all the linefeeds and commas that are not in quotes, with temporary alternatives, then parses the converted text into a list of lists. I thought it was a neat and efficient solution, but the new script took ... much longer than I'd hoped... 93 seconds, but that's still 10 times longer than my old character by character script. Most of the time seems taken taken to get and set items in
a large list, though the actual parsing of text is quite fast.

After mention by Kai and others (thanks) on this list of putting any long list definition in a property within a script object, I made a slight change to my script. I replaced this:

set unquotedList to TextToList of csvQuotedText between quote

with this:

script listHandler
 property unquotedList : TextToList of csvQuotedText between quote
end script

and I replaced any subsequent uses (within a loop) of unquotedList with: unquotedList of listHandler

With this change of one variable, my script's speed improved from 93 seconds, down to 1.3 seconds!!

It worked just as well if I defined the list this way:

script listHandler
 property unquotedList : {}
end script
set unquotedList of listHandler to TextToList of csvQuotedText between quote

In all cases, TextToList is simply:

on TextToList of containerText between delimiter
 set oldDelims to AppleScript's text item delimiters
 set AppleScript's text item delimiters to delimiter
 set textItems to text items of containerText
 set AppleScript's text item delimiters to oldDelims
 return textItems
end TextToList

In conclusion, if I want to speed up the use of long lists in a script, I should define and refer to that list as a script property. That is, instead of defining the list as:

set myLongList to <definition here>

It's better to use:

script listHandler
 property myLongList : <definition here>
end

This actual definition is no faster (and may even be slightly slower). But the overall script speed is greatly improved if the existing items within the list are subsequently referred to many times (eg get or set each item, within a loop of all items).

But it makes no improvement to (and may even slightly slow down) the speed of:

1. Adding items to the list, ie set end in myLongList to

NOR

2. Defining the list, such as using: text items in

I know now that others have summarized similar conclusions before.

Thanks,
Tom

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Importing/parsing CSV files (From: T&B <email@hidden>)

  • Prev by Date: Re: AppleScript in Rosetta
  • Next by Date: Screen Shots
  • Previous by thread: Re: Importing/parsing CSV files
  • Next by thread: Re: Importing/parsing CSV files
  • Index(es):
    • Date
    • Thread