Re: How to parse CSV
Re: How to parse CSV
- Subject: Re: How to parse CSV
- From: Neil Faiman <email@hidden>
- Date: Thu, 24 Jan 2008 07:36:13 -0500
On Jan 23, 2008, at 11:17 AM, Skeeve wrote:
The AppleScript is
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
on run
set started to current date
set {oAStid, AppleScript's text item delimiters} to
{AppleScript's text item delimiters, "|"}
set LoL to {}
repeat with rec in every paragraph of convert(choose file)
copy text items of rec to the end of LoL
end repeat
...
1st Scenario: Seconds elapsed 5 => 80 lines / Second
2nd Scenario: Seconds elapssed 4345 => 2.3 lines / Second
There's a known bug, dating back into the darkest pre-history of
AppleScript, that when you append to a list this way, AppleScript ends
up copying the list anyway, so what looks like an O(N) loop is
actually O(N^2). The standard hack for working around it and getting
the expected O(N) performance is to make the list a property of the
script rather than a local variable of the handler: thus,
on run
property LoL : {} -- this line is the secret
set started to current date
set {oAStid, AppleScript's text item delimiters} to
{AppleScript's text item delimiters, "|"}
set LoL to {}
repeat with rec in every paragraph of convert(choose file)
copy text items of rec to the end of LoL
end repeat
_______________________________________________
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