
VB5, Run-time much slower than Design-time
Quote:
> I was always under the impression that a gosub was as about as efficient as
>one
>could get (a push, run your code, then a pop). I use them extensively rather
>than
>calling subs or functions which I assumed took more overhead.
> What Am I missing here???
If it's true that VB5 generates C source as intermediate code, then the
problem is that C does not have the equivalent of GoSub (because the
corresponding Return can occur in any "subroutine").
If so, the GoSub must be simulated with an explicit stack and extra
labels, rather than using the CPU's native stack. C doesn't allow you to
get the address of a label, so the Return must be implemented as a
(potentially) giant switch statement (roughly equiv. to VB's Select Case)
containing a bunch of goto's.
Why slower? P-code is accessed as data by the interpreter. The
result is it's faster because there is no need to use a switch statement
(with its indexing or comparison overhead) to implement Return. A simple
pop is all that's needed.
Henry S. Takeuchi
Seattle, Washington (USA)