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 Discussion / Writting like a pro - slow?

Author
Message
Zealous
20
Years of Service
User Offline
Joined: 13th Sep 2004
Location: Colorado Springs
Posted: 24th May 2005 11:33
Im trying to keep my code neat and tidy. Im getting in the habit of using more self contained reuseable function, ect... However, ive always wondered something....

Is there any extra slowdown/overhead involved in declaring a variable before you use it? Like xpos as float, ypos as float, ect... at the top of your function instead of just using said variables when you need them? It seems like declaring them is just one extra line in your program, and I dont see how that could possibly HELP the speed.

All you need is zeal
fasdfsdaf
20
Years of Service
User Offline
Joined: 17th Jan 2005
Location:
Posted: 24th May 2005 11:40
Well, the one thing i don't like is that you can only veiw your variables if you put them at the top of your code such as in you examples, so that's why I do it also. But it also helps error checking, you know what the variable should be where, and it's easier to see if you've misspelled it. And it doesn't help or not-help the speed, because they would be read only once when the program starts.

[me]"My throat froze!"
[other person]"Force quit it next time..."
A.K.A Death Stalker
Zealous
20
Years of Service
User Offline
Joined: 13th Sep 2004
Location: Colorado Springs
Posted: 24th May 2005 11:50
So if you had a function you call a million times per loop, it wouldnt hurt the speed to have

xpos as float
ypos as float
ect...

at the start of each function? seems like its a LOT of lines that you dont really NEED.

All you need is zeal
fasdfsdaf
20
Years of Service
User Offline
Joined: 17th Jan 2005
Location:
Posted: 24th May 2005 14:05
To make it easier, just use:



that shouldn't reduce the speed at all, and you cut even more lines.

[me]"My throat froze!"
[other person]"Force quit it next time..."
A.K.A Death Stalker
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th May 2005 16:57
It's actually speeding up the main program flow. If you don't declare your variables, then it has to make them "on the fly". When it encounters a new variable, it has to allocate memory and create it.
If your variables are declared globally, they are created at the beginning, when time isn't as critical.

BatVink

Login to post a reply

Server time is: 2025-05-23 12:49:00
Your offset time is: 2025-05-23 12:49:00