OK- I'm going to make up some numbers to illustrate what I've been saying. Don't take them as anything but illustrations. I haven't had a chance to code up any "benchmarks" to do actual timing, but this should help explain things:
Suppose you were to write a loop that takes a Random number and does nothing but do ABS(number) on it. Run the loop 10,000 times and time how long it takes to run.
Then write a loop that takes a Random number and does
IF number <0 THEN number = -number ; (Does the same thing as ABS() does)
and run it 10,000 times, timing how long THAT takes to run.
When you run the loops, you'll find out how long it takes to run ABS() 10,000 times, compared to running the IF/THEN line 10,000 times, on WHATEVER computer you're running them on.
The loop that takes less time to run will show which method of finding the Absolute Value of a number is faster.
Now take the program to a different computer. One with a far different CPU, a different video card, different RAM, completely different. (Still IBM compatible though.)
Now run the loops again. The time it takes to run 10,000 ABS() on the new computer WILL be different.
This is what you've been saying. A different computer WILL run the code faster or slower than the first one. No problem.
But- what I've been saying is that the second computer will run the OTHER loop, the IF/THEN loop at a different speed too... but they will BOTH be in the SAME RELATIONSHIP as they were on the first computer.
Let me make up some numbers to illustrate this:
Suppose the first computer was a PIII with a so-so video card and 256MB of RAM. Nothing special.
Loop 1 (the ABS function) takes 8 seconds to run 10,000 times.
Loop 2 (the IF/THEN statemsnt) takes 4 seconds to run 10,000 times.
So the first loop takes twice as long as the second loop.
(That means that doing an IF/THEN test is twice as fast as doing an ABS() to get the Absolute Value of a number. Both get exactly the same results, but one method is faster.)
Now go to your friend's "super bleeding edge" game computer. An Athlon 2800XP+ with a top-end Radeon video card, a Gig of RAM and a 333Mhz FSB. Run both loops on that computer.
Loop 1 takes 3 seconds to run on this computer.
Loop 2 takes 1.5 seconds to run on this computer.
You see, you're right- the other computer runs the loops faster.
But notice that Loop 1 is STILL TWICE as fast as loop 2.
Now take the two loops to your grandmother's house and run them on her old P150 computer that she uses to send e-mail with. No special video card and 32MB of RAM. Pretty pathetic.
Loop 1 takes 20 seconds to run on this computer.
Loop 2 takes 10 seconds to run on this computer.
Again, you're right- the slower computer runs the loops slower.
But again- notice that Loop 1 is STILL TWICE as fast as loop 2.
This is what I've been trying to say all along. YES, different hardware runs code at different speeds. YES, the hardware makes a difference how fast code will run.
BUT- code which runs slower than other code on one machine will STILL run slower than that other code on a different machine if it runs without using any external devices.
Even though BOTH sets of code run faster than when they were on the other computer.
The KIND of hardware won't change that.
Loop 1 will ALWAYS be faster than Loop 2 no matter WHAT hardware you run them both on.
The whole point of this whole thing is that if we can find out more of these speed comparisons between equivalent code, then we could use the faster code to make programs run faster on ANY computer than they would with the other (slower) code.
To answer your question:
The code that does both the ABS() and the IF/THEN runs in the CPU chip of the computer.
These are probably good choices of code to use for this discussion because NOTHING ELSE will affect how fast they run on any particular computer.
The machine code that perfoms the ABS() runs entirely inside the CPU. It doesn't use the video card and it doesn't need to use external RAM or the FrontSide Bus. Nothing outside the CPU will affect how fast it completes its task.
The only real factors affecting it are the speed of the CPU and the efficiency of the coding. (That's up to Mark Sibly in the case of Blitz Basic.)
So when you execute ABS() and then the IF/THEN statement, the speed of the CPU chip will be the same (since you're running them both on the same machine), and it won't affect the difference between the two methods of taking the Absolute Value of a number.
The ONLY difference between how fast they run will be the efficiency of the code Mark Sibly wrote.
THAT'S what we're actually trying to get to here- what functions or commands are coded "better" than other equivalent functions or commande.
Now- the LINE versus RECT issue is different.
In that case more of what Andy has said comes into play.
The CPU will have to do calculations on where the points are located, but it will have to involve the video card into actually displaying the line or rectangle.
IF the video card can draw rectangles or lines by itself, then all the CPU has to do is tell it where the starting and ending points are, and the video card hardware will do the rest.
This is very fast and lets the CPU go on and calculate other things while the video card is drawing and displaying the lines and rectangles.
BUT- if the video card can't draw the lines and rectangles by itself (older video cards didn't have as much functionality as newer video cards do these days), then the CPU will have to calculate EVERY point on the line or rectangle and send it to the video card, pixel by pixel.
All the video card would do in this case would be to display the pixels on the screen after the CPU has told it where they need to be to form a picture of a line or rectangle.
So in this case, Andy is right- the different hardware may treat LINE and RECT differently, so maybe one video card would draw lines faster, and another might draw rectangles faster, and we wouldn't be able to know which one to use to make our programs run faster on whatever video card the user owns.
The only way to tell for sure is to actually run tests like I talked about back at the top of this, on a lot of different computers and list the results for people to read and try on their own computers.
And maybe Shambler is right- maybe it would turn out that the differences between equivalent methods of doing the same things isn't enough to bother worrying about them.
But it would be nice to know for certain.
Suppose you were to write a loop that takes a Random number and does nothing but do ABS(number) on it. Run the loop 10,000 times and time how long it takes to run.
Then write a loop that takes a Random number and does
IF number <0 THEN number = -number ; (Does the same thing as ABS() does)
and run it 10,000 times, timing how long THAT takes to run.
When you run the loops, you'll find out how long it takes to run ABS() 10,000 times, compared to running the IF/THEN line 10,000 times, on WHATEVER computer you're running them on.
The loop that takes less time to run will show which method of finding the Absolute Value of a number is faster.
Now take the program to a different computer. One with a far different CPU, a different video card, different RAM, completely different. (Still IBM compatible though.)
Now run the loops again. The time it takes to run 10,000 ABS() on the new computer WILL be different.
This is what you've been saying. A different computer WILL run the code faster or slower than the first one. No problem.
But- what I've been saying is that the second computer will run the OTHER loop, the IF/THEN loop at a different speed too... but they will BOTH be in the SAME RELATIONSHIP as they were on the first computer.
Let me make up some numbers to illustrate this:
Suppose the first computer was a PIII with a so-so video card and 256MB of RAM. Nothing special.
Loop 1 (the ABS function) takes 8 seconds to run 10,000 times.
Loop 2 (the IF/THEN statemsnt) takes 4 seconds to run 10,000 times.
So the first loop takes twice as long as the second loop.
(That means that doing an IF/THEN test is twice as fast as doing an ABS() to get the Absolute Value of a number. Both get exactly the same results, but one method is faster.)
Now go to your friend's "super bleeding edge" game computer. An Athlon 2800XP+ with a top-end Radeon video card, a Gig of RAM and a 333Mhz FSB. Run both loops on that computer.
Loop 1 takes 3 seconds to run on this computer.
Loop 2 takes 1.5 seconds to run on this computer.
You see, you're right- the other computer runs the loops faster.
But notice that Loop 1 is STILL TWICE as fast as loop 2.
Now take the two loops to your grandmother's house and run them on her old P150 computer that she uses to send e-mail with. No special video card and 32MB of RAM. Pretty pathetic.
Loop 1 takes 20 seconds to run on this computer.
Loop 2 takes 10 seconds to run on this computer.
Again, you're right- the slower computer runs the loops slower.
But again- notice that Loop 1 is STILL TWICE as fast as loop 2.
This is what I've been trying to say all along. YES, different hardware runs code at different speeds. YES, the hardware makes a difference how fast code will run.
BUT- code which runs slower than other code on one machine will STILL run slower than that other code on a different machine if it runs without using any external devices.
Even though BOTH sets of code run faster than when they were on the other computer.
The KIND of hardware won't change that.
Loop 1 will ALWAYS be faster than Loop 2 no matter WHAT hardware you run them both on.
The whole point of this whole thing is that if we can find out more of these speed comparisons between equivalent code, then we could use the faster code to make programs run faster on ANY computer than they would with the other (slower) code.
To answer your question:
The code that does both the ABS() and the IF/THEN runs in the CPU chip of the computer.
These are probably good choices of code to use for this discussion because NOTHING ELSE will affect how fast they run on any particular computer.
The machine code that perfoms the ABS() runs entirely inside the CPU. It doesn't use the video card and it doesn't need to use external RAM or the FrontSide Bus. Nothing outside the CPU will affect how fast it completes its task.
The only real factors affecting it are the speed of the CPU and the efficiency of the coding. (That's up to Mark Sibly in the case of Blitz Basic.)
So when you execute ABS() and then the IF/THEN statement, the speed of the CPU chip will be the same (since you're running them both on the same machine), and it won't affect the difference between the two methods of taking the Absolute Value of a number.
The ONLY difference between how fast they run will be the efficiency of the code Mark Sibly wrote.
THAT'S what we're actually trying to get to here- what functions or commands are coded "better" than other equivalent functions or commande.
Now- the LINE versus RECT issue is different.
In that case more of what Andy has said comes into play.
The CPU will have to do calculations on where the points are located, but it will have to involve the video card into actually displaying the line or rectangle.
IF the video card can draw rectangles or lines by itself, then all the CPU has to do is tell it where the starting and ending points are, and the video card hardware will do the rest.
This is very fast and lets the CPU go on and calculate other things while the video card is drawing and displaying the lines and rectangles.
BUT- if the video card can't draw the lines and rectangles by itself (older video cards didn't have as much functionality as newer video cards do these days), then the CPU will have to calculate EVERY point on the line or rectangle and send it to the video card, pixel by pixel.
All the video card would do in this case would be to display the pixels on the screen after the CPU has told it where they need to be to form a picture of a line or rectangle.
So in this case, Andy is right- the different hardware may treat LINE and RECT differently, so maybe one video card would draw lines faster, and another might draw rectangles faster, and we wouldn't be able to know which one to use to make our programs run faster on whatever video card the user owns.
The only way to tell for sure is to actually run tests like I talked about back at the top of this, on a lot of different computers and list the results for people to read and try on their own computers.
And maybe Shambler is right- maybe it would turn out that the differences between equivalent methods of doing the same things isn't enough to bother worrying about them.
But it would be nice to know for certain.