Re: Concatenating records
Re: Concatenating records
- Subject: Re: Concatenating records
- From: Kai <email@hidden>
- Date: Tue, 28 Jan 2003 12:20:26 +0000
on Mon, 27 Jan 2003 00:43:21 -0800, Paul Berkowitz <email@hidden>
wrote:
>
If I'm building up a record by concatenating a new property (label and
>
value) to it, one by one, until I reach perhaps 100 properties, will it be
>
more efficient memory-wise if I concatenate the new property to the end:
>
>
set theRecord to theRecord & {newProperty:"New"}
>
>
than if I do it the other way around:
>
>
set theRecord to {newProperty:"New"} & theRecord
>
>
?
>
>
I would only do this if I can be absolutely certain that the record does not
>
already contain a newProperty, of course, since otherwise nothing will be
>
replaced (left side rules in concatenation). "Just to be safe", I might do
>
it with newProperty on the left in _all_ cases, but I have a lingering
>
instinct, which is probably not rational, that concatenating a record on the
>
left that contains, say, 88 properties with a record on the right that
>
contains 1 property somehow involves less memory re-writing than the other
>
way around. This is probably silly, but I really don't know. Does anyone
>
know for certain?
>
>
I may be building up this 100-item record 3000+ times, so it would add up if
>
there were any difference.
I don't know if this will help, Paul - but I compared the speed of the two
methods OMM. There was a slight but discernible benefit from using the first
method (concatenating a record on the left with a new property on the
right).
For the first test, I built a list of 100 properties - then measured the
time taken to add them, one by one, to an existing record. In the second, I
started with an existing record containing 100 properties - and timed the
addition of just one new record (repeating the operation to simulate the
addition of a new property to many different records). Both tests compared
the two different forms of concatenation.
In all cases, the 'record & new property' method consistently outperformed
the 'new property & record' version. While the precise speed bump could vary
between tests, the average was about 4-5%.
Not the kind of lead, perhaps, to earn a standing ovation - but probably
significant enough over many records. (Certainly suggests that your
instincts, however lingering, are still to be trusted!) ;-)
--
Kai
_______________________________________________
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.