Speed Comparison Post #1 of 2 (Was Fast Drawing) 
Author Message
 Speed Comparison Post #1 of 2 (Was Fast Drawing)

I'm splitting this post up into two different posts.  The second one
contains the entire BASIC program that I'll be referring to. (The image
of Lynda Carter takes up quite a few lines.)

I realized the other day that although I try to read posts in this
newsgroup as often as I can, I don't contribute as often as I probably
should have.  Thought I would remedy that today.

I've seen a few questions lately concerning the fastest way to draw
sprites.  (Images)  One poster pointed out that if the color of the
pixel that you are PSETting to the screen is the same as the current
background color, to not bother plotting it.  Yes, this is probably
obvious to most but I'm sure that somebody wasn't aware of that.

The reason, of course, is that although it would take an extra
instruction within the loop to check this each time...

   IF pixel <> background.color THEN PSET (x, y)

....it is actually FASTER because it takes much more time for the screen
writes than for the extra line of code.  However, one can take this
another step as well as we shall soon see!!

A few years ago I came up with a very efficient algorithm which I am
quite proud of.  I've never seen it posted or discussed anywhere else
although I'm not naive enough to believe that I truly invented it!!

I was creating a DOS puzzle game at the time (The Continuing Adventures
of {*filter*}Box - plug, plug!) on a 33 MHz 486 and after awhile happened to
test my code on my old 286.  Ouch!!  Some of the screen writes were VERY
slow and actually quite disappointing.  On the 486 they were fine but
not acceptable to me on the 286.  Since 286's at the time were still
quite common, I decided I needed to come up with a faster way to draw
these images to the screen.  I did so, which does not involve any
assembly code or any BIOS calls or anything like that.  Just simple
BASIC code which will work with probably every form of BASIC.

The second post contains a program which compares the two different
methods.  The first method is the most common one, one that many of you
I'm sure are using.  I'll call it the "Slow Way."  The second method
within the program is what I came up with, which I'll call the "Fast
Way."

The example program reads a data file into an array.  (The sprite
happens to be a black & white image that I put together this morning of
the beautiful Lynda Carter in a {*filter*} little dress.  Hey, if we're gonna
take the time to see an image, we might as well have some fun, huh?
<grin>).   Although the example image is black & white, the method works
just as well for images with many colors too.

Check out the chart I composed showing the difference in speed between
the two methods.  (Note: all times below are in seconds.)

ELAPSED TIME FOR DRAWING THE IMAGE OF
LYNDA CARTER 100 TIMES ON A 166 MHz Pentium
--------------------------------------
              SLOW WAY    FAST WAY

QBASIC         27.25       23.51
powerbasic     10.92        3.67

ELAPSED TIME FOR DRAWING THE IMAGE OF
LYNDA CARTER 100 TIMES ON A 33 MHz 486
--------------------------------------
              SLOW WAY    FAST WAY

QBASIC         175.83      168.73
PowerBASIC      61.40       25.87

All times are actually the average of three different runs.
Regretfully, I don't have my QuickBASIC disks anymore (or any other
BASIC compilers) so I can't test the speed difference on any other BASIC
dialects.  Maybe someone else would enjoy doing so.  Note that the
elapsed times are going to vary from user to user based on your own
video card and other hardware, etc.

(Note: Without intending to, this chart helps to illustrate why I
switched over to PowerBASIC from QuickBASIC!  PowerBASIC's biggest boast
is indeed it's speed!!)

Anyway, in every case my "improved" algorithm is indeed faster than the
normal "easy" way despite that fact that it takes more lines of code in
the program.   And even though this is written in BASIC, the principle
should work for C, Pascal, and any other language.

If just one person can benefit from the code, or the idea or the
example, it will make my weekend.  An e-mail letting me know would be
most welcome.  Altogether, I probably spend several hours creating the
image of Lynda, writing and testing the code, writing this note, etc.

(Note:  It took awhile to get the image small enough so that it would
work in QBasic.  Originally it was much larger!!  If you're using QBasic
now I STRONGLY recommend spending the money for a better product.)

Enjoy the image of Lynda.  (She's always been a favorite of mine!)

- Ed
http://www.*-*-*.com/ ~ecollins

Note:  I know that Deja News often splits larger posts up into several
smaller posts.  Other news providers may do the same thing.  Since I
know the second post is rather large, I'll make both this post and the
second one available, in one file, from my homepage, since that may be
easier for some people.  To view it, point your web browser to
http://www.*-*-*.com/ ~ecollins/speed.txt



Sat, 13 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)

Quote:
>ELAPSED TIME FOR DRAWING THE IMAGE OF
>LYNDA CARTER 100 TIMES ON A 166 MHz Pentium
>--------------------------------------
>              SLOW WAY    FAST WAY

>QBASIC         27.25       23.51
>PowerBASIC     10.92        3.67

>ELAPSED TIME FOR DRAWING THE IMAGE OF
>LYNDA CARTER 100 TIMES ON A 33 MHz 486
>--------------------------------------
>              SLOW WAY    FAST WAY

>QBASIC         175.83      168.73
>PowerBASIC      61.40       25.87

on a k6-233 with an S3 virge DX -4mb:
QB45               57.33           32.50
PB                   12.02           3.67

As you can see the video card is a major
player in this test.
I am also running under Win98, which
sloes things down vs. Win95 & DOS.
Ska - Honolulu



Sat, 13 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)
On Tue, 28 Jul 1998 09:40:53 -0700, "Edward D. Collins"

Quote:

>A few years ago I came up with a very efficient algorithm which I am
>quite proud of.  I've never seen it posted or discussed anywhere else
>although I'm not naive enough to believe that I truly invented it!!

I've done some tests on my computer... (P200, win95 DOS-box, S3 Virge)
Your original code:

PowerBasic 3.5:
slow -- 13.57
fast --  4.06

QuickBasic 4.5:
slow -- 18.78
fast -- 13.23

As you can see, it's a huge difference with PB.
However, under Screen 13 (probably the most popular mode for GFX stuff)
The difference is virtually nil:

QuickBasic 4.5:
slow - 9.06
fast - 9.00

After modyfying the source a little to use POKE instead of PSET, so it can
be used with PB as well, I get these figures in screen 13:

'slow' PB: 1.37
'slow' QB: 6.0

I've also changed the LINE statement into POKE$ to poke an entire string
into memory under PB, but this did not have the desired effect:

1.96 seconds, vs. 1.37 seconds for individual pixels.

QB does not support the POKE$ function, so this can't be tested.
--

In short: for Screen 12 it looks like a significant difference (especially
under PB. On top if this, poking into memory probably won't make much of a
difference in screen 12, since you would have to change pages all the time)
It safes some precious time.

For screen 13 there are much faster ways of drawing, as the results above
will show you. So, depending on the screenmode you are using, it definitely
can be helpful to use these routines!
--
Marc van den Dikkenberg
-----------------------
The PowerBasic Archives
http://www.xs4all.nl/~excel/pb.html



Sat, 13 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)

Quote:
> Marc van den Dikkenberg wrote

> In short: for Screen 12 it looks like a significant
> difference (especially under PB. On top if this, poking
> into memory probably won't make much of a difference in
> screen 12, since you would have to change pages all the
> time) It saves some precious time.
> For screen 13 there are much faster ways of drawing, as
> the results above will show you. So, depending on the
> screenmode you are using, it definitely can be helpful to
> use these routines!

Marc, thank you for your tests and your comments.

|     ,::::::<
|    ,::/^\"``.       Best regards,
|   ,::/, `   ?`.
|  ,::; |        '.    ___               __     _
|  ;::|  \___,-.  c)  (_  _/   _ _ _/   /  )   / )  //'   _
|  ;::|     \   '-'   /__(/((/(// (/   /(_/.  (__()((//)_)
|  ;::|      \

|  `;:|.=` _.=`\
|    '|_.=`   __\
|    `\_..==`` /
|     .'.___.-'.     Edward D. Collins presents...
|    /   ...    \    his very own homepage!
|   ('--......--')
|   /'--......--'\   http://www.inficad.com/~ecollins
|   `"--......--"'



Sat, 13 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)
On a Pentium 100/w Matrox Millenium 4Mb Video
                         SLOW WAY    FAST WAY

QBASIC                 43.94       39.32
QB4.5 interpreted     30.92      21.37
QB4.5 compiled        16.44       9.89
PDS7 interpreted      34.00       22.90
PDS7 compiled 286 optimized
                                16.19       9.39

It seems that PB has the all time record here. Did the PB results reflect a
compiled or interpreted condition, or does it matter in PB?

HK

Quote:



>>ELAPSED TIME FOR DRAWING THE IMAGE OF
>>LYNDA CARTER 100 TIMES ON A 166 MHz Pentium
>>--------------------------------------
>>              SLOW WAY    FAST WAY

>>QBASIC         27.25       23.51
>>PowerBASIC     10.92        3.67

>>ELAPSED TIME FOR DRAWING THE IMAGE OF
>>LYNDA CARTER 100 TIMES ON A 33 MHz 486
>>--------------------------------------
>>              SLOW WAY    FAST WAY

>>QBASIC         175.83      168.73
>>PowerBASIC      61.40       25.87

>on a k6-233 with an S3 virge DX -4mb:
>QB45               57.33           32.50
>PB                   12.02           3.67

>As you can see the video card is a major
>player in this test.
>I am also running under Win98, which
>sloes things down vs. Win95 & DOS.
>Ska - Honolulu



Mon, 15 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)

Quote:

> On a Pentium 100/w Matrox Millenium 4Mb Video:
>                            SLOW WAY   FAST WAY
>                            --------   --------
> QBASIC                       43.94     39.32
> QB4.5 interpreted            30.92     21.37
> QB4.5 compiled               16.44     9.89
> PDS7 interpreted             34.00     22.90
> PDS7 compiled 286 optimized  16.19     9.39
> It seems that PB has the all time record here.
> Did the PB results reflect a compiled or
> interpreted condition, or does it matter in PB?

My results listed previously were with a compiled program, but if I
remember correctly, there is no difference in speed when it comes to
PowerBASIC with compiled programs vs. interpreted programs.  I'd have to
dig out my old PowerBASIC manuals to be sure, but I seem to remember
that was one of the many "advantages" to PB.  The programs ran at the
same speed even after they were compiled.

It's nice to see that so many people took the time to run that program
on their own systems and come up with their own figures.  I enjoyed
seeing the faster times of my little "algorithm."  Thanks.

|     ,::::::<
|    ,::/^\"``.       Best regards,
|   ,::/, `   ?`.
|  ,::; |        '.    ___               __     _
|  ;::|  \___,-.  c)  (_  _/   _ _ _/   /  )   / )  //'   _
|  ;::|     \   '-'   /__(/((/(// (/   /(_/.  (__()((//)_)
|  ;::|      \

|  `;:|.=` _.=`\
|    '|_.=`   __\
|    `\_..==`` /
|     .'.___.-'.     Edward D. Collins presents...
|    /   ...    \    his very own homepage!
|   ('--......--')
|   /'--......--'\   http://www.inficad.com/~ecollins
|   `"--......--"'



Tue, 16 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)
On Thu, 30 Jul 1998 23:11:31 -0600, "Har-D-Har-Har"

Quote:

>It seems that PB has the all time record here. Did the PB results reflect a
>compiled or interpreted condition, or does it matter in PB?

PB/DOS automatically compiles each program before running.
It's a blazingly fast compiler, so this takes very little time.
--
Marc van den Dikkenberg
-----------------------
The PowerBasic Archives
http://www.xs4all.nl/~excel/pb.html


Tue, 16 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)
PB does not have a "interpreted" mode. Wether you Run in the IDE or Compile
and then run from within or from the resulting .exe file, it is compiled.
 ---Barry
Quote:


>> On a Pentium 100/w Matrox Millenium 4Mb Video:

>>                            SLOW WAY   FAST WAY
>>                            --------   --------
>> QBASIC                       43.94     39.32
>> QB4.5 interpreted            30.92     21.37
>> QB4.5 compiled               16.44     9.89
>> PDS7 interpreted             34.00     22.90
>> PDS7 compiled 286 optimized  16.19     9.39

>> It seems that PB has the all time record here.
>> Did the PB results reflect a compiled or
>> interpreted condition, or does it matter in PB?

>My results listed previously were with a compiled program, but if I
>remember correctly, there is no difference in speed when it comes to
>PowerBASIC with compiled programs vs. interpreted programs.  I'd have to
>dig out my old PowerBASIC manuals to be sure, but I seem to remember
>that was one of the many "advantages" to PB.  The programs ran at the
>same speed even after they were compiled.

>It's nice to see that so many people took the time to run that program
>on their own systems and come up with their own figures.  I enjoyed
>seeing the faster times of my little "algorithm."  Thanks.

>|     ,::::::<
>|    ,::/^\"``.       Best regards,
>|   ,::/, `   ?`.
>|  ,::; |        '.    ___               __     _
>|  ;::|  \___,-.  c)  (_  _/   _ _ _/   /  )   / )  //'   _
>|  ;::|     \   '-'   /__(/((/(// (/   /(_/.  (__()((//)_)
>|  ;::|      \

>|  `;:|.=` _.=`\
>|    '|_.=`   __\
>|    `\_..==`` /
>|     .'.___.-'.     Edward D. Collins presents...
>|    /   ...    \    his very own homepage!
>|   ('--......--')
>|   /'--......--'\   http://www.inficad.com/~ecollins
>|   `"--......--"'



Sat, 20 Jan 2001 03:00:00 GMT  
 Speed Comparison Post #1 of 2 (Was Fast Drawing)

Quote:

>>> It seems that PB has the all time record here.
>>> Did the PB results reflect a compiled or
>>> interpreted condition, or does it matter in PB?

Edward D. Collins replied:

Quote:
>> My results listed previously were with a compiled
>> program, but if I remember correctly, there is no
>> difference in speed when it comes to PowerBASIC
>> with compiled programs vs. interpreted programs.
>> I'd have to dig out my old PowerBASIC manuals to
>> be sure, but I seem to remember that was one of
>> the many "advantages" to PB.  The programs ran
>> at the same speed even after they were compiled.

Barry Erick noted:

Quote:
> PB does not have a "interpreted" mode. Wether
> you Run in the IDE or Compile and then run from
> within or from the resulting .exe file, it is compiled.

Barry, you are correct.  I should have phrased my answer differently and
for the record I shall do so now:

"My results listed previously were with an actual executable program but
if I remember correctly, with PowerBASIC, there is no difference in
speed with a program that is compiled to an actual EXE file vs. a
program that has yet to be compiled to an EXE and is simply run in the
IDE (Integrated Development Environment).

I'd have to dig out my old PowerBASIC manuals to be sure, but I seem to
remember that was one of the many 'advantages' to PB -- these two types
of programs ran at the same speed."

Better?

Best regards,

Ed



Sat, 20 Jan 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Speed Comparison Post #2 of 2 - quite large (Was Fast Drawing)

2. Speed of SQL Comparisons

3. X-basic speed comparison

4. I need a FAST string comparison in VB

5. Job Post Comparisons, 11/95 & 2/96

6. Need a FAST String Comparison!

7. Floating Point Speed - Comparison of VB 5.0, Delphi 3.0, and VC 5.0

8. Speed comparison with VB3 & 4-32bit

9. Speed comparison of VB4

10. Speed of string comparisons in VB 3.0 Pro

11. Comparison speed Access/SQL/ other database format

12. 3rd Post: I am at my Wit's End

 

 
Powered by phpBB® Forum Software