» Home » VB Fibre
Site
News
Files

Visual Basic
Strings
Math
General
Properties
Memory
Methods

Search
Testing

Inline ASM-VB
Strings
Math
General
Memory

Search
Using inline ASM
Submit!

Fixed vs Variable length concatenation

New speed record! Atleast 53215.9% performance gain here !!

We dim one Variable length string, and one fixed length string.
Then we are going to add 1 character to each string, for 65526 times.

Declarations:
Private VariableLengthString As String Private FixedLengthString As String * 65526

Code:
For I = 1 To lngIterations '//Run test '//Set an element in the string to the desired value Mid$(FixedLengthString, I) = "X" Next I

Code:
For I = 1 To lngIterations '//Run test '//Concatenate a character to the variable length string VariableLengthString = VariableLengthString & "X" Next I
And it works perfect. Now there are a few minor things about fixed length strings.

-They're max 65526 characters;
-The filesize will increase
-They will always take up that amount of memory, what their length is.

Thanks to Andre van Wyk for letting me know a while ago!

Variable % faster than Fixed Variable (sec) Fixed (sec)
85961.3% 12.814183 0.01489
53215.9% 10.246895 0.019219
72034.2% 11.075419 0.015354
67692.7% 9.976452 0.014716
70734.3% 10.390809 0.014669


User contributed notes:

Author: VBBR () Date: 22:03 31/03/2004
Why did you use Mid$ for a test and & for the other? I think this can deturpate the results.

Author: Almar Joling () Date: 22:03 31/03/2004
Because that was the way to do it for this test. :). End result is the same.

Author: EACam (empyrianpale at juno dot com) Date: 22:04 21/04/2004
Unfortunately, having to constantly Trim$() the strings and file size being HUGE...I don't find the speed gain worth the work gain.

Author: PRoPHEZZoR (Name_Here_No_Spam at HaCKERMAiL dot COM) Date: 11:08 24/08/2004
Trim$() don't take that much CPU, BTW it's even better to use one of the string-manipulation classes on pscode anyway...

Author: Almar Joling () Date: 11:08 24/08/2004
VB Fibre is about using native VB functions (and inline ASM) and not using API's/typelibs. Prefer to keep things compact :)

For other functions there's always "VB Speed" (check google)

Author: PRoPHEZZoR (p at h dot c) Date: 21:08 24/08/2004
Bam! In my face! :-)

Author: Tom (hurendo_kun at hotmail dot com) Date: 14:05 31/05/2005
Ah, these test results are extremely ambiguous. I agree that fixed-length strings are faster than non-fixed strings, but you seem to be missing the point by using different concatenation techniques. To be more specific, the technique you chose for the non-fixed string specifically exploits its flaw: memory re-allocation and copying. I suggest you find a technique you can use on both to produce less biased results.

Author: Merri () Date: 16:02 19/02/2006
For this comparison to be more equal, the variable length string should be filled to the final size with String$, because the fixed length string is always of the given size... it is full of null characters. If you do FixedString = "x", the end result is x and a ton of null characters (except if the fixed length string is only one character long).

So, you have to take this limitation into account when making a comparison.

Author: TheShau (shauros at walla dot com) Date: 14:08 04/08/2006
Without any regards to strings, or not and vb or not, ALWAYS pre allocate large data..... ALWAYS

Add user-note
Author:
E-mail (optional):
Anti spam, please enter 'ok' without quotes:
Comment: