Fetching list items, and speed thereof

I came across a novel way (for me, at least) of dealing with items in a list.
To see if it made any difference i ran a comparison with the method I would unthinkingly use.
Here’s the full test script:

-- http://macscripter.net/viewtopic.php?id=41285
property loopCount : 8000
set looptimes to {}

run script (do shell script "python -c 'import time; print time.time()'") -- dummy
set t1 to run script (do shell script "python -c 'import time; print time.time()'")
set t2 to run script (do shell script "python -c 'import time; print time.time()'")
set time_calib to t2 - t1

set removeTags to {"t1", "t2"} -- tags to remove
set currentTags to {"t1", "pip", "bes", "t2", "gek"} -- set of tags
set newTags to {}

set t1 to run script (do shell script "python -c 'import time; print time.time()'")
repeat loopCount times
	-- first method
	-- http://forum.devontechnologies.com/viewtopic.php?f=20&t=10617#p69209
	repeat until currentTags = {}
		set oneTag to first item of currentTags
		set currentTags to rest of currentTags
		if oneTag is not in removeTags then set end of newTags to oneTag
	end repeat
end repeat
set t2 to run script (do shell script "python -c 'import time; print time.time()'")
set end of looptimes to t2 - t1 - time_calib


set removeTags to {"t1", "t2"} -- tags to remove
set currentTags to {"t1", "pip", "bes", "t2", "gek"} -- set of tags
set newTags to {}

set t1 to run script (do shell script "python -c 'import time; print time.time()'")
repeat loopCount times
	-- 2nd method
	repeat with aTag in currentTags
		if aTag is not in removeTags then set end of newTags to contents of aTag
	end repeat
end repeat
set t2 to run script (do shell script "python -c 'import time; print time.time()'")
set end of looptimes to t2 - t1 - time_calib

looptimes
--> typically {0.01, 20}

What’s going on here? I can’t believe what I’m seeing.

Hi.

At the end of the first repeat, newTags contains 3 items. At the end of the second, it contains 24000 items. That may have something to do with it. :slight_smile:

Argh. I feared it would be something trivial. And it was.:confused:

Typical result, after mending: {0.01, 0.4}. So that 1st method is quite a bit faster. I suppose that’s because the 2nd method has to fetch items twice in each pass, which the first method avoids.