I had many months ago as part of a project I'm working on (performance
pre-processor for UniBasic).
I've recreated a (no-scientific) test to get some rough numbers.
X=0
LOOPS = 999999
STIME = SYSTEM(9)
FOR I = 1 TO LOOPS
X += 1
NEXT I
CRT SYSTEM(9) - STIME
X=0
STIME = SYSTEM(9)
FOR I = 1 TO LOOPS
GOSUB INC.X
NEXT I
CRT SYSTEM(9) - STIME
STOP
INC.X:
X += 1
RETURN
This results in:
385
608
So when an loop + addition takes 0.38 micro seconds
The gosub adds an extra 0.22 micro seconds
But, that isn't the whole truth. If you have a look at the byte code
BASIC produces, you can clearly see that it adds 4 bytes for each line
to indicate the line number. When it performs jumps (such as gosubs) it
always jumps to the appropriate byte position that is left in the byte
code to indicate the line number of the label.
So, this means the above measurements are measure the overhead of the
extra line identifies as well (which is fine in practice)
The below code compensates for that:
X=0
LOOPS = 999999
STIME = SYSTEM(9)
FOR I = 1 TO LOOPS
X += 1
X += 1
X += 1
X += 1
NEXT I
CRT SYSTEM(9) - STIME
X=0
STIME = SYSTEM(9)
FOR I = 1 TO LOOPS
GOSUB INC.X
NEXT I
CRT SYSTEM(9) - STIME
STOP
INC.X:
X += 1;X += 1; X += 1;X += 1
RETURN
Now we are comparing a loop, 4 additions and 4 lines vs a loop, a
GOSUB/RETURN, 4 additions and 4 lines.
The results:
939
1048
Or, the GOSUB/RETURN takes .11 microseconds.
It's quite clear from the above timings that the line count is a bigger
performance overhead then using GOSUB/RETURN
Sorry for the overkill :)
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of DavidJMurray
(mvdbs.com)
Sent: Tuesday, 8 February 2011 10:08 AM
To: [email protected]
Subject: Re: [U2] Does UV have a "BLOCK" command
Has anyone measured the overheads of the various methods of subroutine
calls within UniBasic?
Is it of significance?
djm
Kate Stanton wrote:
>
> Why not use a subroutine?
> Personally, I like subroutines!
>
>
-----
Learn and Do
Excel and Share
http://mvdbs.com http://mvdbs.com
--
View this message in context:
http://old.nabble.com/Does-UV-have-a-%22BLOCK%22-command-tp30867376p3086
8821.html
Sent from the U2 - Users mailing list archive at Nabble.com.
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
###########################################################################################
The information transmitted in this message and attachments (if any) is
intended only
for the person or entity to which it is addressed. The message may contain
confidential
and/or privileged material. Any review, retransmission, dissemination or other
use of
or taking of any action in reliance upon this information by persons or
entities other
than the intended recipient is prohibited. If you received this in error,
please
contact the sender and delete the material from any computer.
The intended recipient of this e-mail may only use, reproduce, disclose or
distribute
the information contained in this e-mail and any attached files with the
permission of IMB.
###########################################################################################
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users