VBGamer |
|
RE: Redefining variables in a type statement Adam Hoult (0 replies, 0 views) (2000-Jun-16) Yeah, i did some benchmarks for a quick test which simply sets a variant with an integer, and one which reads back out. Then used a standard integer instead of a variant for the non variant test. Finally i did a variant test of Reading out a STRING from the integer stored in the variant. (And the same for a standard integer to string using VB's own conversions)
(tests performed on a PIII-450 inside the IDE, not compiled EXE)
Here are the results (from which you can extrapolate to your needs) obviously we only do one READ and one WRITE of/to the variant, and is directly proprtionate to the number of READ's and WRITE's we do per itteration of your loop
Variant Integer results
1 million WRITE Itterations 250ms
1 million READ Itterations 250ms
10 million WRITE Itterations 2453ms
10 million READ Itterations 2404ms
Standard Integer Results
1 million WRITE Itterations 171ms
1 million READ Itterations 190ms
10 million WRITE Itterations 1742ms
10 million READ Itterations 1903ms
Variant Integer to String Type Change
1 million Itterations 1863ms
10 million itterations 18587ms
Standard Integer to String Type Change
1 million itterations 1332ms
10 million itterations 13493ms
So while there is no HUGE speed hit for simple Read/Write operations (there is a small one) when using variants, type changes however are expensive. Now for the original question, this wouldn't really matter as you wouldn't be changing types, you would simply be setting the variant with a new type (in any case it will clear the old variant type first, whether you set it with the same type as before, or a new type).
So what does all this crap mean ?? Well say your game was running at 60fps, and you set a variant once every time round, your write operation should take approx 0.015ms per frame (not bad) and setting an integer would take 0.0114, so does it really matter ?? Thats up to you, but Variant types waste memory, so use sparingly. (i.e dont have an array of 100,000 of these suckers =) (Also remember that to keep a constant frame rate of 40fps your entire loop must take no more than 25ms (1000/Projected FrameRate))
Adam |