Menu

#53 Speed-up function calls, subroutine calls and gosubs [r887]

Unstable_(example)
open
None
5
2017-07-23
2017-07-23
No

Hi Jim,

This update speed-up function calls, subroutine calls, and gosubs.

for x=1 to 1000000
gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a:gosub a
next x
print msec
end

a: return

Results: 3300ms vs 11500ms

Also, introducing "Unexpected RETURN" error.

print 1
return
print 2

Before: Exits without warning at line 2
After: Throw the error message "ERROR on line 2: Unexpected RETURN." and exits.

This message is very useful in a real program to understand what is happening.

#do some stuff
gosub routine

#do some stuff
call sub()

#do some stuff
gosub routine

#do some stuff
call sub()

subroutine sub()
print "This is SUBROUTINE"
end subroutine

print "program successfully get here"

routine:
print "This is GOSUB"
return

print "but never here..."

#do some stuff

Respectfully,
Florin Oprea

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.