Re: Problems with speed & "Info For"
Re: Problems with speed & "Info For"
- Subject: Re: Problems with speed & "Info For"
- From: Kai Edwards <email@hidden>
- Date: Sat, 16 Feb 2002 22:49:26 +0000
on Thu, 31 Jan 2002 08:43:03 -0800 (PST), Brian Johnson
<email@hidden> wrote:
snip: discussion about speed comparisons between AS's 'info for', the
Finder's 'kind of' and Tanaka's 'xResolver'.
>
The "info for" solution is actually lots faster (11 vs 3 seconds in a 500
>
count repeat loop) if the target folder is small (38 items, 1.4MB).
>
Interestingly, if the target is an alias to the folder or a file, it takes
>
longer (14 v. 9 and 15 v. 10, respectively) and if it's a simple file they
>
come out about equal (10 v. 10). For now, the "info for" solution seems
>
like the winner, even if the resulting script is fairly slow in some
>
cases.
Many apologies for not coming back sooner on this, Brian. I started playing
with some further tests and was called away on other matters (hey - gotta
make a living)!
One of my reasons for returning to this thread is that I'm also doing some
stuff that could benefit from these comparisons - and I figure the results
may be worth sharing.
From other discussions, we've already seen how different hardware/software
configurations can influence not only speeds (which is one reason I prefer
to express results as an index) - but also the relationship between results.
(Perhaps the lesson here is to use the experiences of others as a guide but
- wherever possible - carry out our own tests to confirm that any
performance 'promises' are actually delivered by our target system.)
Of the methods explored thus far, my own tests largely confirmed your own -
in that 'info for' generally delivers pretty acceptable results. However, as
folders grow larger and nesting sinks deeper, initially tolerable times can
begin to stretch beyond the bounds of one's patience...
The 'info for' method (which calculates folder sizes - whether you want it
to or not) is particularly vulnerable when analysing the contents of larger
folders - especially when they're buried deep within a filing hierarchy.
Essentially, if your script has to 'walk' through several folder levels, the
size of the buried ones will usually be recalculated at every level above
them, too.
In view of this, it seems sensible to explore a few other methods of
analysing larger, nested folders - to compare any relative strengths and
weaknesses.
Of the alternative analysis methods suggested, I opted to try:
1) Akua's 'basic info for' (Paul Berkowitz, Scott Norton)
2) Finder items by type (Nigel Garvey)
Although I also planned to include some Finder filtering methods (items of x
whose y = z, etc.), these proved to be a little too unpredictable on the
system I was using at the time. (However, that doesn't mean to imply they
can't be very useful in certain situations!)
Many of the results that follow involved a 1,000 times repeat loop -
executed 10 times to produce a pretty reliable average. (So most figures are
the result of 10,000 runs.)
For practical reasons, the number of repeat loops in test 3 (below) had to
be reduced. (As the scripts and file structures became more complex - the
test times began to stretch beyond the practicable.) However, the 10-test
average was applied in all cases.
-------- TEST 1 - get info for item types --------
The first test was a simple exercise in getting information about 4
different item types. Here, AppleScript's 'info for' was compared directly
with Akua's 'basic info for'. The timed commands were simply <info for
theItem> and <basic info for theItem> respectively.
The results were expressed as an index: 100 = slowest time...
basic
item info info
type for for
--- --- ---
alias of file 88 94
file 87 93
alias of folder 66 88
folder 41 100
Perhaps it's worth mentioning that the Finder's 'kind of' was also tested
here. But since the fastest result from 'kind of' was about 16 times slower
than the slowest figure above, there seemed little point in detailing the
results.
From the tabled figures, it seems the overhead of an OSAX call rendered the
Akua method slightly slower. The differences were most noticeable when
comparing the results for a folder. (However, since the folders were empty,
AppleScript's 'info for' had no extra size calculations to contend with -
hardly a real-world example!)
-------- TEST 2 - get info by folder contents --------
So what happened when a folder began to fill up with items?
The next series of tests was carried out on a folder to which items were
added progressively. The timed commands were the same as for test 1 (<info
for theItem> and <basic info for theItem>). Again, the results were an
index: 100 = slowest time...
basic
folder info info
contents for for
--- --- ---
0 items 15 37
4 items 18 37
8 items 21 37
16 items 26 37
32 items 36 37
64 items 58 37
128 items 100 37
As before, the Akua times were longer when the folder contained no or few
files. However, the results from 'info for' rose in proportion to the number
of items within the folder. The advantages of 'basic info for' became more
attractive as folder contents increased - with results so consistent that
they charted as a horizontal line.
With folders containing a total of 32 items or more, then, the Akua OSAX
really began to pay dividends.
Incidentally (in case you're wondering), item size vs. item count was also
tested. For example, the size of the folder that contained 4 items was 1,466
bytes. Another folder, also containing 4 items - but this time weighing in
at 5,385,872 bytes - produced the following results...
5MB basic
folder info info
contents for for
--- --- ---
4 items 18 37
- exactly the same as the smaller folder. So the size of items within a
folder appeared to have no effect on speed - while the quantity of items
profoundly affected the performance of 'get info'.
-------- TEST 3 - list items by type --------
Finally, to bring into play another analysis method (Finder item types),
some scripts were needed to enable comparisons of roughly similar results
from each method (albeit achieved in different ways).
Since I'm not entirely clear about your specific aims, each test was
scripted to simply list 3 different types of item within a given folder. OK,
the lists produced in each case weren't exactly the same - but I wanted to
avoid extra conversions which may have been unfair to one particular method
or another.
Also, in case any method might have been inadvertently 'compromised' by
clumsiness in my scripting (not uncommon!), the timed sections of each
script are detailed below - so that you can judge/compare/adapt for
yourself.
The variable 'x', which was defined before the timer was started, represents
the path to the containing folder...
--------- SCRIPT 1 - 'info for' ----------
set {aliasList, folderList, otherList} to {{}, {}, {}}
set checkList to list folder x
repeat with n in checkList
set theItem to alias ((x as string) & n)
set theInfo to info for theItem
if theInfo's alias then
copy theItem to aliasList's end
else if theInfo's folder then
copy theItem to folderList's end
else
copy theItem to otherList's end
end if
end repeat
------------------------------------------
------ SCRIPT 2 - 'basic info for' -------
set {aliasList, folderList, otherList} to {{}, {}, {}}
set checkList to list folder x
repeat with n in checkList
set theItem to alias ((x as string) & n)
set theKind to (basic info for theItem)'s kind
if theKind = an alias then
copy theItem to aliasList's end
else if theKind = a folder then
copy theItem to folderList's end
else
copy theItem to otherList's end
end if
end repeat
------------------------------------------
----- SCRIPT 3 - 'list Finder items' -----
tell application "Finder"
set {aliasList, folderList, docList} to [NO BREAK]
{x's alias files, x's folders, x's document files}
end tell
------------------------------------------
Again, these tests analysed the contents of a folder to which items were
added progressively. The figures are also an index: 100 = slowest time...
basic list
folder info info Finder
contents for for items
--- --- --- ---
0 items 0 0 14
4 items 3 3 15
8 items 6 7 15
16 items 12 13 15
32 items 23 25 17
64 items 46 50 19
128 items 92 100 23
(Of course, the initial zeros for 'info for' and 'basic info for' were not
really nil values - but relatively low figures masked by index compression
and rounding.)
At first glance, it might appear that 'basic info for' was fairly
consistently pipped at the post by 'info for'. However, any sub-folders
within the analysed folder were empty - so the results of test 2 (above)
would need to be factored in for a more realistic evaluation/comparison.
When the folder contained only a few items, the hit incurred by calling the
Finder appeared to put 'list Finder items' at a distinct disadvantage.
However, as the folder's contents rose above 20 items, this method started
to pay increasing dividends.
------------------------------------------------------
If all this proves anything, it's probably that the 'best' or 'fastest'
methods can depend heavily on prevailing circumstances. Each method in the
last 2 tests had both advantages and disadvantages - and their charted
performance curves varied substantially.
Whenever a script's performance becomes an issue, I guess we really need to
learn about the various different methods that could achieve our aims - and
then test and compare them for ourselves in the context of the specific
target system/configuration.
Finally, apologies for the length of this note - but I hope you can glean
something of use from it. I'll try harder to be more succinct in future!
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
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.