Page 1 of 2

Execution Speed: a striking observation on my PC!

Posted: Sat Oct 29, 2005 6:56 pm
by Dräc
Here a program which displays a series of sprites on the screen at each loop and indicates the elapse time spend.
If I carry out the program 2 times, without removing them, I note that the elapse time spend by the second instance is shorter than the first one.

Why ??!!!
Is it the same observation for you?

Caution: It is clear that the performance depend largely on the computer configuration. Probably with current standard conf, you do not see anything, but with my poor PIII 500 and Win98, I feel a clear difference: I have a factor 20 to 200!
It is probably a problem of memory management. But I cannot say if it is a Win98 or a PB problem.
It is very uncomfortable for the gameplay of my game in which I refreshed the map each loop. :evil:
Moreover, it is especially an intrinsically inextricable situation. :?

Does somebody have an explanation and a solution?

Code: Select all

InitSprite()

  #Width=32
  #Height=32
  #WindowWidth=22*#Width
  #WindowHeight=14*#Height
  #NbDisplaySprite = #WindowWidth/#Width * #WindowHeight/#Height
  #NbSprite = #NbDisplaySprite
  
  If OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "Boxes") And OpenWindowedScreen(WindowID(), 0, 0, #WindowWidth, #WindowHeight, 0, 0, 0)
    AddKeyboardShortcut(0,#PB_Shortcut_F1, #PB_Shortcut_F1)
    
    For k = 0 To #NbSprite-1
    CreateSprite(k, #Width, #Height, #PB_Sprite_Memory)

      If StartDrawing(SpriteOutput(k)); Dessine le Sprite
        y = 0
        #StepX = 2
        StepY = Round(#StepX*#Height/#Width, 0)
        For x = 0 To #Width/2 Step #StepX
          Box(x, y, #Width-2*x, #Height-2*y ,RGB(Random(255),Random(255),Random(255)))
          y + StepY
        Next x
        ;Locate(#Width/3, #Height/3) : DrawText(Str(k))
        StopDrawing()
      EndIf
    
    Next
    
    ;Affichage des sprites
    Repeat
      k=0
      tps = GetTickCount_()
      For x = 0 To #WindowWidth-1 Step #Width
        For y= 0 To #WindowHeight-1 Step #Height
          DisplaySprite(k, x, y)
          DisplaySprite(k%#NbSprite, x, y)
          k+1
        Next
      Next
      tps = GetTickCount_() - tps

  
      If  StartDrawing( ScreenOutput() )
        Locate( 0, 0)
        DrawText( "TPS:"+Str(tps) )
        StopDrawing()
      EndIf 
      FlipBuffers()

      Delay(100)

    Until WindowEvent() = #PB_Event_CloseWindow
  EndIf
Second edition: I have put a Delay(100)

Posted: Sat Oct 29, 2005 6:57 pm
by dell_jockey
during the second run, (parts of) your code is still cached, hence the speed increase.

Posted: Sat Oct 29, 2005 7:17 pm
by Dräc
Normally, the two codes are independent. No resource shared!
What do you mean?

Posted: Sat Oct 29, 2005 7:35 pm
by dell_jockey
if the compiled code is small, it could be that both routines are loaded into second level cache and remain there after ending the first run. The second run would be much faster, as the loading/paging into second level cache isn't needed anymore.

Posted: Sun Oct 30, 2005 2:36 am
by Dräc
I afraid, there is a misunderstanding.
To clarify let me expose again my problem:
If you launch the program to have two executions simultaneous, i.e. two windows displayed on the screen, one of them display a TPS very different from the other (on my computer).
Noticed that TPS value of a window can slightly fluctuate

A little screen capture to illustrate:
Image

Re: Execution Speed: a striking observation on my PC!

Posted: Sun Oct 30, 2005 4:23 am
by PB
> with my poor PIII 500 and Win98, I feel a clear difference

For what it's worth, I have a PIII 667 and Win2K, and when I run your code
I get 130 or 140 every time, so maybe it's Win98 problem? (I also tried to
run your code as an exe with Win98 under Virtual PC but it kept crashing
with an Illegal Operation error, so I don't know).

(BTW, why does your 500 mhz get more TPS than my 667 mhz? :cry:
Maybe I should just go back to Win98 again to avoid the Win2K bloat).

Re: Execution Speed: a striking observation on my PC!

Posted: Sun Oct 30, 2005 10:20 am
by Dräc
PB wrote:when I run your code
I get 130 or 140 every time, so maybe it's Win98 problem?
Thanks for testing.

Thus you have two windows opened and both of them display closed TPS values ?
No significant difference?

Someone can do the test with Win98 please ?

Re: Execution Speed: a striking observation on my PC!

Posted: Sun Oct 30, 2005 11:10 am
by PB
> you have two windows opened and both of them display closed TPS values ?

Sorry, I didn't test two windows at the same time. But this time I did, and
here's the results:

When both are open and the first has the focus, it has 250 (on average) and
the second non-focussed one has 430 on average.

When both are open and the second one has the focus, then the first one
has an average of 430 while the second one has an average of 250.

(In these tests, "first" means the first instance, and "second" means second).

Make of that what you will. :)

Posted: Sun Oct 30, 2005 11:53 am
by dell_jockey
indeed, I obviously didn't quite understand the question...

So the window that's not in focus, has the higher frame rates, although the window that has focus should have higher priority, right?

If both windows overlap like on Dräc's bitmap, the following could be the case: for the window that is overlapped by the top window (the one in focus) Windows does some optimization, by only drawing what needs to be drawn. In that case, the non-focus window might get higher frame rates, because not all of its window contents needs to be drawn.

Posted: Sun Oct 30, 2005 2:54 pm
by Lep
I tested it on Windows 98, running both windows at the same time and got values from 30-32 on both.

Posted: Sun Oct 30, 2005 3:09 pm
by Dräc
First, thank you to all for the tests.

Believe me or not, but I haven’t this behaviour with the windows focus.
Windows kept their TPS values either focused or not!

In fact, the bigger TPS value is on the first opened window, and the next opened windows display a same value but lower then the first one…

Completely crazy on my computer.

@Lep, which processor have you ?

Posted: Sun Oct 30, 2005 3:10 pm
by Lep
P3 500mhz

Posted: Sun Oct 30, 2005 3:24 pm
by Dräc
Aaaaarg! I’m dead! What is going wrong with my configuration ?…

Posted: Tue Nov 01, 2005 3:06 am
by Sub-Routine
Hang on, the TPS you are displaying is Ticks per Sprite, so the higher numbers mean the sprites are slower. Exactly the opposite of frame rate.

Rand

Posted: Tue Nov 01, 2005 3:48 am
by PB
> the TPS you are displaying is Ticks per Sprite

I didn't even look closely at the code, and just assumed TPS was the
French version of FPS -- LOL! :)