CLS - speed measuring!

BlitzMax Forums/BlitzMax Beginners Area/CLS - speed measuring!

LuckyBargee(Posted 2011) [#1]
Hi, All!

I supposed, that CLS is a very slow function, but when I tried to measure it, I've got a problem. The CLS() function didn't want to work properly without... DrawText() function! When you put Drawtext() after Cls() everything was Ok, but if you try to use only Cls() the computer hung.

What should I do to measure the Cls() speed correctly?

Have a look the code:

' ---------------------------
SuperStrict

Global time1:Long=0
Global bb:Long=0
Global width:Int=800, height:Int=600, depth:Int=16, freq:Int=60

SetGraphicsDriver GLMax2DDriver()
Graphics(width,height,depth,freq,GRAPHICS_BACKBUFFER)

time1=MilliSecs()
Repeat
Cls()
'DrawText("Text",10,20)
Cls()
'DrawText("Text",10,20)
Cls()
'DrawText("Text",10,20)
Cls()
'DrawText("Text",10,20)
Cls()
If (MilliSecs()-time1) > 1000 Then Exit ' 1 sec
bb=bb+1
Forever
Print "Times=" + bb
Print "Times/5000=" + bb/5000
' ---------------------------


Midimaster(Posted 2011) [#2]
you only have the feeling it would hang. Fact is, it runs so fast, that it eats all performance. It remains no timer for Windows to handle MouseEvents.

You should always add a timer, that prevents BMax form eating all performance:

Graphics 800,600
FPS=CreateTimer(60)
Repeat
     Cls
     Flip 0
     WaitTimer FPS
Until KeyHhit(Key_Escape)



LuckyBargee(Posted 2011) [#3]
Thank you, Midmaster, for the nice idea!

On the contrary, if you check the time, you will see that Cls(),Cls(),Cls(),Cls(),Cls() will take much more time, than Cls(),Drawtext(),Cls(),Drawtext(),Cls(),Drawtext(),Cls(),Drawtext(),Cls(),Drawtext() !!! Why?

And the question still exists: How to measure the Cls() speed?

I used the same approach and by now I've measured Drawtext(), DrawImage(), DrawRect(), SetcColor, but Cls()!


Czar Flavius(Posted 2011) [#4]
??????????? Why are you trying to measure Cls speed? When would you need to use more than 60 Cls a second?

Depending on the system and options, there may be a limit to the number of Cls you can call per second. That may be why it is seeming slow.

Edit: I confused Cls with Flip, but I guess my point still stands!

Last edited 2011


Floyd(Posted 2011) [#5]
If you really want to measure Cls speed then the loop should not call Millisecs() or KeyHit() or other "System" routines, which may also use significant amounts of time. I would suggest using a large, fixed number of calls to Cls, something in this style:
time=MilliSecs()
For n = 1 To 10000
	Cls
Next
time = MilliSecs() - time



Midimaster(Posted 2011) [#6]
The speed of Cls is high! On my yery slow notebook below 1/500000 sec. Why do you want to speed it up?

The problem is your test. First test with 100, then with 1000 then with 10000 and you will see that the graphic card will get problems with too much CLS's commands

with 100 0msec
with 1000 1msec
with 10000 >5000msec

So the time results of a too long test will say nothing about the real speed of one CLS.

SuperStrict
Graphics 800,600
Global time%=MilliSecs()
Global Maxi%=100 ' Or 1000 Or 10000
For Local n% = 1 To Maxi
	Cls
Next
time = MilliSecs() - time
Print time



LuckyBargee(Posted 2011) [#7]
Thank you.

1. "??????????? Why are you trying to measure Cls speed?"

I'm working on a project where I have to output a big stuff at the screen between two flips(-1). So, I have up to 16 msec to do it and I have to be sure about it, especially if the user has a very old computer... .

2. "The speed of Cls is high!"

You right! That's it! "the graphic card will get problems with too much CLS's commands"!

Let's try the full screen and 16 depth. Why? Because this modes influence on the Cls() speed results. For example, depth 32 takes more time...

Try to run my code from the first post. There are only 5 times Cls(), but you will wait for 5 minutes! May be the speed of Cls() is high, but why we wait for so much and why we can't get "1/500000 sec" speed in my example?
However, if we put Drawtext() after Cls() in the example above, the speed will be Ok: the result will appear immediately. Why is Cls() so special?


xlsior(Posted 2011) [#8]
This really is pointless - by definition you will never need to do more than one CLS each frame, at which point it's pretty much intantaneous. For argument's sake, just assume it takes 0ms and continue on.


Czar Flavius(Posted 2011) [#9]
If your users are using a very old computer, then the speed of Cls is the least of your worries.

The first question is, do you need to do a Cls? For example, if you draw a background image that fills the entire screen, or the screen is filled with tiles etc, then you don't need it.

If you do need it, then that's what you need. You can't really do much about the cost of something you must do.


LuckyBargee(Posted 2011) [#10]
Thanks to everyone,

I've got it!
:)