Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

optimization techniques... 1

Status
Not open for further replies.

Barok

MIS
Dec 13, 2002
134
CA
Recently I have been looking for god optimization tutorials on the net to give me that extra bit of speed for programs that are slow. I have found two tutorials (one is a set of five, the other can be found at can anyone point me to some tutorials or maybe give me a few tips?
 
Use SUBs instead of Labels.

Don't use GOSUB/GOTO

Use modules

Develop a working code and then rethink the algorithm and modify it so that no.of lines reduce. Repeat this process as many times as possible

Instead of using donkey methods to calculate things use mathematical formulae

Use dynamic arrays
 
could you explain "donkey methods?"
 
Donkey method refers to using the computer's ability to repeat a task to calculate things. For example to find the sum of 'n' numbers having a constant difference(Arithmetic Progression) you could use either repeat the calculation like:
a% = 1: b% = 3
for i% = 1 to 10
a% = a% + b%
b% = b% + 2
next
The above prog. will calculate the addition of first 10 odd nums.(I think. I didn't try it but I think it will work)

Or you could use a mathematical formula(which I forgot) which directly gives the sum of numbers in arithmetic progression.
 
Use Integers where-ever possible...
DEFINT A-Z

Use look up tables instead of calculating...
Multiplication and Division are SLOW...
For these types of calculations, try to set up a look-up table to use instead of caculating in real time...
this works good for things such as Divideing by 2,3,5... and things such as Sine, Cosine...

For the SIN & COS...
DIM SinT(360) as Single
DIM CosT(360) as Single
For I = 0 to 360
SinT(I) = Sin(I * (3.1415/180))
CosT(I) = Cos(I * (3.1415/180))
Next

Then you can use it like this...
X = SinT(45) * 10
...instead of this...
X = Sin(45 * 3.1415 / 180) * 10
...which saves you 3 calculations (especially the /)...

The other good use for a Look-up table is divide maps...
Take the max possible number... (such as 255)
Take the number you are going to divide by (such as 5)
and multiply them together... 255 * 5 = 1275

Dim Div5(1275) as integer
For I = 1 to 1275
Div5(I) = I \ 5
Next

This is especially good when dealing with graphics, due to the number of calculations required in a minimum amount of time...
Addition & Subtraction are cheap so you can do this...
avg = Div5(num1 + num2 + num3 + num4 + num5)
...and still save time over this...
avg = (num1 + num2 + num3 + num4 + num5) \ 5

QB + Assembly Language...
The other tip is to look into assembly language, to directly control the computer. For the QB interface, you can use libraries, or CALL ABSOLUTE, and CALL INTERUPT (for QB4.5)
The Ups & Downs...
CALL INTERUPT...
Allows you to access hardware, such as your mouse, within QB...
only allows you to deal with dos interupts...
CALL ABSOLUTE...
allows you to directly use the computers resources...
but, requires the assembly code to be converted to Hex codes...
Assembly Libraries...
Able to use any assembly commands (16 / 32bit)...
You have to assemble your code into an .OBJ file, then use LIB.EXE to create a .LIB and a .QLB file for use in QB, You also have to have QuickBasic 4.5, so you can load the library with the /L option and Compile it.

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Hey...

That was written by Toshi Horie

He was one of the best QB optimizers/Demo makers...

The only person better (he even admits it) is entropy ;-)

He could Make QB stuff look like It was written in C without using libraries like DQB, Future, Cosmo...

I scanned through it... It's a pretty good paper...

Thanks for posting that agual Starz 2 U

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
I believe i've heard of entropy before, but not toshi. I recall i've read some of entropy's tutorials on clipping and making a tile engine, but they weren't really that good. Not that descriptive.

No asm or lib's... those days are gone now. Nowadays, everyone uses libraries, assembly and such. Too bad neozones is gone as well...
 
*I don't...

(everyone is a pretty BIG word...)

the only lib I use is qb/l

...because the idiots @ m$ left a few things out of qb4.5 ;-)

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
oooh, yeah, i've been to his page before. and i've also read his tut on optimization. It's quite good. surprisingly, there are only two optimization tut's out there. one is a set of five, one is a huge one (toshi's). Toshi's site is nice but i wish it was a little better organized.

Stupid Microsoft. The wireless mouse/keyboard combo i'm using is brand new, but it's got a few big defects in it, such as, that the mouse drains batteries like no tommorow, and the keyboard keys always stick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top