No, I think I get the point. Basically we're all talking about the same thing.
Theoretically, yes, concatenation and then writing to a buffer might be slower, but at the same time doing multiple writes to a buffer would have the same amount of overhead unless we assumed that the buffer was pre-allocating blocks of memory.
If the buffer was pre-allocating chunks of memory than it should be much faster to make multiple write calls than to concatenate and then make a single write.
But the problem here is we are talking about two seperate processes. That process communications isn't factored in in the above theory.
Code:
Without communications:
Concatenation: print x + y + z
allocate space for x, assign x
reallocate the space, assign y to the end
reallocate the space, assign z to the end
assign incoming value to buffer (already allocated)
clear buffer
prints: print x; print y; print z
assign x to buffer
assign y to buffer
assign z to buffer
clear buffer
Now with communications:
Concatenation: print x + y + z
allocate space for x, assign x
reallocate the space, assign y to the end
reallocate the space, assign z to the end
send new string to outside object
receive value, assign incoming value to buffer (already allocated)
clear buffer
prints: print x; print y; print z
send x to outside object
receive x, assign x to buffer
send y to outside object
receive y, assign y to buffer
send z to outside object
receive z, assign z to buffer
clear buffer
So without an outside object we have:
(number of strings) * (MAllocTime + AppendTime) + (AppendTime * NumberOfWrites)
The decision for this one is fairly obvious. In order to limit this the most we can we need to cut down on the number of strings used with each call (concatenation) and send them seperately (multiple writes). The decision point is:
(MAllocTime + AppendTime) vs AppendTime
with the first argument obviously being larger than the second in every scenario.
But with an outside object holding the buffer:
(number of strings) * (MAllocTime + AppendTime) + NumberOfWrites * (AppendTime + CommTime)
We now have a third variable. For the moment we will assume that the Append time is the same for both Strings and the Buffer in our outside object.
The decision point here is less obvious because we have more factors. The decision point is now:
(MAllocTime + AppendTime) vs (AppendTime + CommTime)
which can be factored to:
MAllocTime vs CommTime
Now we actually need to know implementation specifics in order to make a decision. If the memory allocation time is better than the communications time, then we will want more string concatenation and less Writes. If the Communications time is less than the memory allocation time, then we will want to concatenate less and use more writes.
So the real question is which is faster, memory allocation or communications?
Unfortunately I don't see an easy way to test this off the top of my head, at least not for VBScript.
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website