Qbasicnews.com
February 22, 2020, 06:23:07 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: Code optimization tips and stuff.  (Read 6548 times)
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #15 on: May 15, 2003, 10:30:38 PM »

I'm calling my eye doctor tomorrow!
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #16 on: May 15, 2003, 10:50:27 PM »

anyways, you still don't have a point. What if I want mod 1000, or say mod 1515?
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Blitz
I hold this place together
*****
Posts: 853



WWW
« Reply #17 on: May 16, 2003, 10:20:39 AM »

Oh and the obvious things, which i way to to often see people who're not aware of.

Do not call a routine to move say just one object, make a routine that moves all of the objects in that same call. QB subs/functions are horribly slow, it amazes me that back then when qb was made cpu power was a something you had very little of. Yet they made qb which produces such bad code and does so stupid things. Ok, compiler technology wasn't very advanced back then. But it does so many stupid things that just goes against common sense. What were they thinking?

And Agamemnus, just give it up ok? If you have to use it, then you have to use it. Thus me saying "avoid it" and not "don't use it, i'll kill you if you do!!%". But there's always a better way, programming is inventing. And if an inventor can't invent, then he/she is pretty screwed aren't they ?
Logged

oship me and i will give you lots of guurrls and beeea
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #18 on: May 16, 2003, 12:46:53 PM »

Fine, I will, but AND 2^n is not always a substitute for MOD...... and you offer no alternative.

So you ought to say "you should avoid MOD if your number is represented in binary form as a one and a bunch of zeroes."
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #19 on: May 16, 2003, 02:10:39 PM »

And Blitz didn't say "always".  He said "when".  (That word, conceptually, is sort of like the word "if".)
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
toonski84
__/--\__
*****
Posts: 2567



« Reply #20 on: May 16, 2003, 02:24:17 PM »

i think somebody should lock this thread before glenn has a heart attack and gouges his eyes out.

LOWDOWN:
Smiley - AND is faster than MOD when applicable
Smiley - "\" - integer division... faster than "/" but only returns integers
Smiley - ffix makes floats nearly as fast as integers on pentium computers
Smiley - integer operations are always faster on 486s
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
R@dioman
Ancient QBer
****
Posts: 410



« Reply #21 on: May 16, 2003, 03:26:14 PM »

I learned a neat trick for using angles from the wolfeinstein source code. Use only 256 degrees for a full circle because then you don't have to do the old: If Ang < 0 then Ang = Ang + 360 blah blah
you can just use AND. I haven't tried it yet but it seems like a good idea.
Logged

wizardlife
Na_th_an
*****
Posts: 1456


WWW
« Reply #22 on: May 16, 2003, 03:51:27 PM »

Quote from: "R@dioman"
I learned a neat trick for using angles from the wolfeinstein source code. Use only 256 degrees for a full circle because then you don't have to do the old: If Ang < 0 then Ang = Ang + 360 blah blah
you can just use AND. I haven't tried it yet but it seems like a good idea.


That's a good idea... hadn't thought of that... I guess you'd have to use up some memory making trig lookup tables for a 256 degree circle.
Logged

Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #23 on: May 16, 2003, 03:52:56 PM »

However, they probably couldn't get much worse than they are.  And "AND" is faster then MOD if it's not applicable; it just wouldn't matter much then.  Smiley
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
toonski84
__/--\__
*****
Posts: 2567



« Reply #24 on: May 16, 2003, 05:09:18 PM »

...(nitpickers  :roll: ).
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #25 on: May 16, 2003, 05:30:30 PM »

.
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
seph
Na_th_an
*****
Posts: 1915



« Reply #26 on: May 18, 2003, 07:54:33 PM »

Don't know if any of this has been posted before, but I'll post it anyways.

This is the stuff I noticed I have been doing ever since I came back from Perl/PHP/HTML/MySQL to Qbasic 4.5 once more:

- If you have lots of data that may vary, put it in a file.
- If you have small ammounts of constant (static) data here and there, keep it in the program itself. (Use this for things such as the mouse$ DATA.)
- Always use the least ammount of lines. If you have an IF ... END IF statement with only one line in it, make it one line long instead of 3!
- Write subroutines/subprograms/libraries whenever you feel the need to. Do NOT shove all your code into the main program. If you are a serious programmer, you will be repeating a lot of your functions many times over, so SUB them!
- When making a subroutine/subprogram/library, consider how many options you are going to want/need in the future! For example, if you're making a graphical PRINT function, consider things you might want later like alignment, size, location, colour, etc.
- If you need something done, download it from the internet and study how they did it. It doesn't hurt to learn new methods and techniques.
- Don't bother trying to learn what the hell the machine language means (when using CALL INTERRUPTs or CALL ABSOLUTEs and such) because then you will get distracted and start learning ASM and never finish your damn program! Just know that certain DATA (mixed with certain ax%) performs certain functions...
- TYPEs are good, but not always. If you have a TYPE with only 2 or 3 variables inside it, there's probably a better way to do it. If you have all fixed-length variables and only 1 varied-length variable, put the fixed-length ones in the beginning and the varied-length one at the end, and you can parse it out within your functions. This is useful for libraries as well, because it makes it harder for people to take your library variables and make their own functions for them, etc. If that doesn't make sense, then don't mind me, I'm high.

I have to go watch Igby Goes Down now. I heard so many good things about it. See ya.
Logged

earn.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #27 on: May 18, 2003, 09:52:25 PM »

good that you all are saying that a lot of these things should be applied only when it's better to use them. And it is true.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #28 on: May 19, 2003, 03:26:15 AM »

Seph:

Slow:

Code:


     if X=0 and Y=1 and Z=3 then
     End if



Faster: (They call this "Short Circuit"

Code:


    If X=0 then
        if Y=1 then
             if Z=3 then
             End if
        End if
   End if

Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #29 on: May 22, 2003, 11:29:54 PM »

Now, if you had a *real* compiler...


*runs away and hides from big bad QBers with guns*
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!