Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Are Functions slower?

Author
Message
Maxi
13
Years of Service
User Offline
Joined: 20th Jul 2012
Location:
Posted: 28th Jul 2012 18:41
Hello,
I am currently programming a game in which you run around in 3rd person view of the player, and i had the code for collision detection and jumping etc. set up in subroutines, so my main "do-loop" would not be as messy. I also have some subroutines, that i use in different situations, so they require some parameters.

Yesterday i converted those subroutines to functions (because of the parameters). The code still works, but whenever i walk (so i use the functions) it is much slower and laggyer.

Can anyone please give me advice on how to avoid that, or if the functions ARE the problem?

(if you need to see the code specificly, i could send you, it is very long though)

Thank you,
Maxi
Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 29th Jul 2012 02:44
Quote: "Yesterday i converted those subroutines to functions (because of the parameters). The code still works, but whenever i walk (so i use the functions) it is much slower and laggyer.

Can anyone please give me advice on how to avoid that, or if the functions ARE the problem?"

We'd have to see the functions and how they're called in order to help you. Functions are normally equal in performance though.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Jul 2012 04:57
We'll have to see some code to know why.

Functions are a tad bit slower. If you pass arguments to the function it gets significantly slower. With that said though they are still ridiculously fast, especially with the computers we have today. There's no way you'd notice any difference.

It's more important to have good structure in your code than speed.

TheComet

Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 29th Jul 2012 17:05
Functions are in fact slower than subroutines same as arrays are slower than simple variables but unless you are trying to squeeze every ounce of speed out of a specific task for example a FloodFill function it doesn't matter.

Maxi
13
Years of Service
User Offline
Joined: 20th Jul 2012
Location:
Posted: 30th Jul 2012 01:24
I got the problem sorted out;
it was that i tried to call a function as a subroutine, what didn“t give me an error, just made everything way slower :/

Thank you anyway for your help, thats still good to know in the future

Login to post a reply

Server time is: 2026-07-07 12:26:29
Your offset time is: 2026-07-07 12:26:29