array bounds checking

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I know this is likely overly hopful, but I was wondering if anyone knows a
way to turn off array bounds checking in VBA? I know that it can be done in
VB, but I haven't come across away to do it in VBA.

Thanks,
Will
 
Pieter Wijnen said:
why on earth would you want to do that?

To increase the speed of the application.
If the compiler has to check the execution
of every array assignment, it slows the machine down
incredibly. Relieving the machine of that burden speeds
things up but places more responsibility on the
programmer to make sure (s)he won't be writing to
areas of memory other than where the array is stored.

Tom Lake
 
To increase the speed of the application.
If the compiler has to check the execution
of every array assignment, it slows the machine down
incredibly.

It slows things down, but not incredibly.

It might slow it down, but the amount is insignificant in 99% of the cases.
The fact that ms-access does NOT have a native compile option like VB6 is
really a moot point.

MS-access is capable of executing about 30 MILLION instructions per second
on a computer today. Actually, even more then that.

The problem is that ms-access application have not been processor bound for
about 10 years now. If you take a ms-access application, and put in a new
super duper processor, YOU WILL NOT SEE ANY improvement in performance.

Why?

Well, because ms-access is going to be waiting for the network, or the disk
drive, or memory. (mostly the OS, and the disk drive). So, adding more
processing will do nothing for speeding up the application. MS-access spends
all of it times waiting for other parts of the OS.

Given that ms-access can execute about 30 million instructions..I can't
imagine a array of a few hundred elements EVER making any different in a
ms-access application. An array of 100 elements can be looped in

100 elements / 30 million instructions per second = 0.000003

That is .3 millionth of a second for an array of 100 elements. IF you could
turn array bounds checking, and say it runs 2 times faster, we would be
saving .15 millionth of a second. Great, we doubled the speed of the loop,
but it only results in .15 millionth of a second. Really, this is VERY
insignificant.

mean, a user will not even notice 1000 of second...we are talking about
millionth of a second...

So, it does NOT speed things up incredibly. (even if the loop runs 2 times
as fast). Further about 90% or more of the time in ms-access is actually
spent waiting for the os, and other stuff, so, basically, we are talking
about 10% of that .15 million of the second that we could benefit by turning
off array bounds checking.

Unless you are doing some special data modeling and processing in ms-access,
and NOT working with a database which is limited by the disk drive, then I
can't see any reasonably reason, or benefit from being able to turn off
array bounds.

If you actually do need to do this, then I suspect you are ruing the wrong
tool here....
 
While I admire your insite into my specific coding project... In my case...
it actually matters... bounds checking is taking about 50% of my processing
time... there are very clean loops that avoid disk access by preconstructing
data grids before interations... Sure we can write outside modules... but...
the purpose of using VBA is speed of development for a very dynamic
application... so... If anyone happens to know any tricks for disabling array
bounds checking I'd still love to hear about it. :)
 
WillDur said:
While I admire your insite into my specific coding project... In my
case...
it actually matters... bounds checking is taking about 50% of my
processing
time...

You mean to say that 50% of the processing is being used by array bounds
checking?

No way........

How much do you expect to gain my turning off array bounds checking in the
compiler?. As I mentioned, what % of your code is spent in the code that
checks the array bounds. My guess, would be about 1%, or perhaps 2% max.

Further, turning off array bounds checking will give you about 8%..(that is
tops WHEN your compiler has that option. Further, the benefits are only
going to be realized ONLY ON THE LINES of code that actually ref the
array..).

What the above means if you are processing 500 000 000 (500 million
elements), then you are going to save about 5-8% at most. Lets be nice, and
take a figure of about 8%

That means in a 100 seconds of processing the loop, you will save 8 seconds.
Really, not significant at all. And, since a computer can process those 500
million elements in about 2 seconds, then 10% of that would about .2 of a
second. (2 tenths of a second is not very much...and is if you are
processing 500 million elements).

Are you really telling me that you are processing more then 500 million
elements in a array? I would like to see that. How many elements are you
processing? (at least admit that number)

As the numbers and math stand now, you are look at about a savings of .2 of
second here for every 1/2 billion elements processed.. Really, very
insignificant.

In fact, I would have to guess that those numbers you are processing come
from some file, or somewhere ? Where does such a large amount of numbers
come from? Are you really processing 500 million elements?

Take your example loop, and place it into VB...and try compiling with the
array bounds turned off. You not going to get more then 10%.

If you are REALLY unconvinced of the above, then simply post the routine
that loops..and I be able to give you a real serious analyses of exactly how
much you can expect to gain...

Sorry to be blunt, but array bounds checking is NOT going to give you any
significant amount of reduction of time for your code....at most 8%.

So, you are chasing something with a false believe that you can expect some
gains in your code execution speed...and you will not...

Of course, as mentioned, we don't have the option anyway.

I you don't believe the above, then post your code...we will go though line
by line, and build a table of each line...and what % of that line of code
you will save by having array bounds turned off.

Now, if you are not doing any type of i/o, then I would certainly concede
that a native compile would help. Roughly a factor of 6-12 times faster..and
that is significant. However, even with a native compiler..turning off the
array bounds checking is not going to give you more then 10% ....

Sorry, that is just the way it is...no matter how you slice and dice it...
 
WillDur said:
While I admire your insite into my specific coding project... In my case...
it actually matters... bounds checking is taking about 50% of my processing
time... there are very clean loops that avoid disk access by preconstructing
data grids before interations... Sure we can write outside modules... but...
the purpose of using VBA is speed of development for a very dynamic
application... so... If anyone happens to know any tricks for disabling array
bounds checking I'd still love to hear about it. :)

What is your evidence that bounds checking is taking 50% of the time?

The bounds checking code would be highly optimized assembly language.
If that code takes 50% of the time, this would imply that you are doing
hardly anything else in your VBA code! Conversely, if you /are/ doing
lots of other things in your VBA code, then, there's no way that the
bounds checking could possibly take as much as 50% of the time.

Not that I think it will help, but, try googling on:

"array bounds checking" vb OR vba

I think the structure behind the scenes, is called a SAFEARRAY. Try
googling on that also.
 
I will say that if we had a native compile option, in some cases, that would
be the cats meow...

Remember, VBA actually shares the SAME compiler base as VB6. We just don't
have the compiler optimizations, and turning off array bounds checking is a
option in VB6...but ONLY for the native compile option.

And, in testing turning off the option in vb6, I find you can get about a
10% boast in performance. So, on 10 seconds of processing, you save one 1
second. Or, in a 100 seconds, 10 seconds of time.

I don't consider that a large amount...but, the original poster may very
well consider that a large gain.

So, I don't want to be un-kind to the original poster...and gains are to had
with this type of option...
The bounds checking code would be highly optimized assembly language.

Yes, I agree!!!

ms-access is really the in-between guy..and it just makes calls to all those
built in libraries anyway. Even when you native compile..those same
libraries are *often* called....

As mentioned, with a native compile option, and heavy looping code...you
acutely get 10, 12 times....sometimes even more of a increase in speed with
a native compile option. So, for looping stuff....native compile is REALLY
a big deal. 10 times means 30 minutes takes only 3 minutes....a huge deal...

However, for the most part, ms-access applications are not processor bound.
The original poser seems to have one of those applications that are in fact
processor bound......

And, in fact, in general looping code, if you turn off all of the checks
(overflow, floating point issues etc..), then VB6 native code actually runs
as fast as compiled c++ code!! (I am not kidding - and had many arguments
and discussions on this!!!). Native compiled vb6 is REALLY fast....just as
fast as c++!!!

However, *just* turning off array bounds checking....about 10%.....

The original poster also made mention of not wanting to use a external .dll.
I would consider using VB6 if the routines are taking a VERY long time, but
then I have to ask where did the data come from. Certainly some gains can be
had here if the array can be passed to a external routine....

I would not bother with this approach unless the number of elements
processed is large, at least 500,000 elements or more...

So,note well TC, I made the above post since I did not want to sound too
hard on the original poster. And, I am open to ideas here. However, I just
think that array bounds checking alone is not the sweet ticket to fixing
performance here, and you also concur with this view......
 
I was focussed on his "50%" comment. It does not make logical sense, to
me. If he is doing any other significant processing, there's no way
that the array bounds checking could possibly take 50% of the time,
IMHO.

But as he seems to have disappeared, I guess that we shall never know!
 
Back
Top