Re: FYI:Timings of AppleScripts
Re: FYI:Timings of AppleScripts
- Subject: Re: FYI:Timings of AppleScripts
- From: Brent Baisley <email@hidden>
- Date: Mon, 9 Feb 2004 15:07:00 -0500
When you are doing scripting or programming, you always want to avoid
the overhead of establishing and closing a connection another program.
Your final script only connects to iTunes twice, so it only needs to
open and close 2 connections. When you had things inside the repeat
loop you had to open and close 10,000 connections (5,000 songs x 2
(album, artist)). That is a lot of overhead.
I'd be curious if changing your script a little more to take iTunes
even further out of the equation would speed things up a little more.
After all, the only thing you need from iTunes is the Album and Artist
list, but you have your entire script running inside iTunes. It may or
may not make a difference, but I'd be curious.
set albumArtistList to {}
set albumAddList to {}
tell application "iTunes"
set albumlist to (album of every track of library playlist 1) as list
set artistList to (artist of every track of library playlist 1) as list
end tell
set theCount to count of albumlist
repeat with i from 1 to theCount
set thisAlbum to item i of albumlist
if albumAddList does not contain thisAlbum then
set thisArtist to item i of artistList
set end of albumAddList to thisAlbum
set end of albumArtistList to thisArtist & ";" & thisAlbum
end if
end repeat
albumArtistList
On Feb 6, 2004, at 12:16 PM, Mark Dawson wrote:
Grabbing the album list from the program (vs inside the repeat loop)
dropped the time from 183 seconds down to 32 seconds. Moving the "set
thisArtist to item i of artistList" line from after the "set thisAlbum
to item i of albumlist" to after the "if" dropped the time down to 18
seconds.
So, in my case, there was a 10x (183 seconds->18 seconds) improvement
in speed by adjusting the algorithm!
As an FYI, here is my "final" AppleScript that grabs both the artist
and album, with no duplicate albums, and executes in 18 seconds (on a
5000 track iTunes library)
tell application "iTunes"
set albumArtistList to {}
set albumAddList to {}
set albumlist to (album of every track of library playlist 1) as list
set artistList to (artist of every track of library playlist 1) as
list
set theCount to count of albumlist
repeat with i from 1 to theCount
set thisAlbum to item i of albumlist
if albumAddList does not contain thisAlbum then
set thisArtist to item i of artistList
set end of albumAddList to thisAlbum
set end of albumArtistList to thisArtist & ";" & thisAlbum
end if
end repeat
end tell
albumArtistList
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.