Re: Settings backup script
Re: Settings backup script
- Subject: Re: Settings backup script
- From: Shane Stanley <email@hidden>
- Date: Fri, 03 Aug 2001 13:52:41 +1000
On 3/8/01 12:05 PM +1000, Nigel Garvey, email@hidden,
wrote:
>
It's the characters of a string that are counted by default, so 'number of
>
MyComments', or 'length of MyComments', or 'count MyComments' will tell you
>
how many characters there are in the string. The expression 'number of
>
characters of MyComments' is the same as 'number of (characters of
>
MyComments)'. It first makes a list of the individual characters - eg. {"H",
>
"e", "l", "l", "o"} - and then counts the items in the list. The answer's
>
exactly the same, but it uses more memory and takes a little longer.
I'm not entirely convinced of this, although I'm open to persuasion. But if
I run the following script:
set x to "The wiley brown fox scripted his way around the lazy black dog."
set time1 to the ticks
repeat 10000 times
set a to characters of x
end repeat
set time2 to the ticks
repeat 10000 times
set a to count of characters of x
end repeat
set time3 to the ticks
repeat 10000 times
set a to length of x
end repeat
set time4 to the ticks
repeat 10000 times
set a to count of x
end repeat
set time5 to the ticks
{time2 - time1, time3 - time2, time4 - time3, time5 - time4}
I typically get something like {117, 13, 12, 10}. This suggests to me that:
(a) "count of characters of" doesn't actually build a list, given how long
just building a list takes;
(b) getting "length of" is not appreciably faster than "count of characters
of"; and
(c) although "count of" is the fastest method, there's not much in it.
I guess this might be one of those things that varies with AS versions, and
the test is simplistic, but the difference between the first two times is
pretty dramatic.
--
Shane Stanley, email@hidden