• 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: Slow vs faster
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slow vs faster


  • Subject: Re: Slow vs faster
  • From: Axel Luttgens <email@hidden>
  • Date: Sat, 8 Jan 2011 18:20:58 +0100

Le 8 janv. 2011 à 12:11, Nigel Garvey a écrit :

> Axel Luttgens wrote on Sat, 8 Jan 2011 11:33:01 +0100:
>
>> Le 8 janv. 2011 à 11:21, Nigel Garvey a écrit :
>>
>>> [...]
>>>
>>> I found the second version faster too. At first I assumed it was because
>>> of the different kinds of repeat, but the major contributor seems to be
>>> the coercion to alias in the second version. Remove it from the second
>>> version, or introduce it into the first, and they run at very nearly the
>>> same speed.
>>
>> Hello Nigel,
>>
>> It thus seems we are disagreeing. ;-)
>> Could you post the code you have tested?
>
> Hi, Axel.
>
> I tested the very handlers posted by Luther, in separate scripts, with
> identical lines in the implicit run handlers to set the top folder of
> the hierarchy (as alias) and to time the handler calls. The tests were
> run from AppleScript Editor in OS 10.6.6 with all Finder windows
> initially closed. Both scripts were run a couple times to "run them in"
> before the actual timing runs. The hierarchy itself is inside my
> Documents folder and contains six subfolders, each each of which
> contains various numbers of sub-sub- and sub-sub-sub-folders. (85
> folders in all, including the root.)
>
> Typical timings for Luther's first handler: 7.3 seconds; for the second:
> 6.1 seconds. Up to 0.4 seconds variation in the results.


Thanks Nigel,

I thus tested:

	tell application "Finder" to close windows
	set S to current date
	recursivehandler1(path to applications folder)
	set T to (current date) - S
	tell application "Finder" to close windows
	display dialog T

	on recursivehandler1(folderAlias)
		tell application "Finder"
			-- open window of folderAlias
			-- do lots of stuff to window of folderAlias here
			-- then ...

			copy (sort folders of folderAlias by name) to folderList
			repeat with innerFolder in folderList
				select innerFolder
				my recursivehandler1(innerFolder) -- and many other parameters
			end repeat

			-- close window of folderAlias
		end tell
	end recursivehandler1

in one window of AppleScript Editor, and:

	tell application "Finder" to close windows
	set S to current date
	recursivehandler2(path to applications folder)
	set T to (current date) - S
	tell application "Finder" to close windows
	display dialog T

	on recursivehandler2(folderAlias) -- and many other parameters
		tell application "Finder"
			-- open window of folderAlias
			-- do lots of stuff to window of folderAlias here
			-- then ...

			copy (sort folders of folderAlias by name) to folderList
			repeat with i from 1 to (count items of folderList)
				set innerFolder to (item i of folderList) as alias
				select innerFolder
				my recursivehandler2(innerFolder) -- and many other parameters
			end repeat

			-- close window of folderAlias
		end tell
	end recursivehandler2

in another window (OSX 10.6.6 here too).

And yes, I observe shorter execution times with the second script too: about 40 vs 30 seconds.
And I now have to agree with Nigel: the Finder really seems to handle aliases quicker than its own references!

I thus tried above scripts on a PPC box running 10.5.8. I had to change:
	copy (sort folders of folderAlias by name) to folderList
into:
	copy (sort (get folders of folderAlias) by name) to folderList
and to perform the test on "/Developer/usr" instead of "/Applications", so as to have a sufficient level of folder nesting.

Execution times now were closer to the ones I would have expected: about 48 vs 54 seconds.
That is, a slight inefficiency of aliases compared to Finder references.

So, it looks like we are facing a new behavior.
Could this be a side-effect of the move towards a Cocoa Finder?

Axel

 _______________________________________________
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

References: 
 >Re: Slow vs faster (From: "Nigel Garvey" <email@hidden>)

  • Prev by Date: Re: New to AppleScript,please help.
  • Next by Date: Re: Slow vs faster
  • Previous by thread: Re: Slow vs faster
  • Next by thread: Increasing numbers
  • Index(es):
    • Date
    • Thread