» 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!

Single vs Multi dim arrays

Single arrays are much faster.
Probably the more dimensions, the faster the single dimension array is in comparison. If I increase the number of iterations, the difference would probably get bigger as well.

Declarations:
Private myArray1(10000) As Long Private myArray2(100, 100) As Long

Code:
Public Sub TestOne() Dim lngX As Long, lngY As Long For lngY = 0 To 100 - 1 For lngX = 0 To 100 - 1 myArray2(lngX, lngY) = 1 Next lngX Next lngY End Sub Public Sub TestTwo() Dim lngX As Long, lngY As Long, lngCalc As Long '//Same as using X,y For lngY = 0 To 100 - 1 lngCalc = (lngY * 100) '//Normal multi dim width For lngX = 0 To 100 - 1 myArray1((lngX + lngCalc)) = 1 Next lngX Next lngY End Sub

Single % faster than Multi Single (sec) Multi (sec)
29.6% 0.896483 0.691485
28.6% 1.050448 0.817123
15.6% 0.960848 0.831025
14.5% 0.998089 0.871410
47.6% 1.062180 0.719528


User contributed notes:

Author: Tom (hurendo_kun at hotmail dot com) Date: 16:06 08/06/2005
This is true for older chipsets, but it doesn't seem to hold for newer ones. A similar profile on my system with one-, two-, and three-dimensional arrays yielded comparable results for each. (However, this may be attributed to my dimensions, which were powers-of-two. Using powers-of-two provides better memory alignment and thus yields faster performance.)

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