Execution Speed: a striking observation on my PC!

Everything else that doesn't fall into one of the other PB categories.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Execution Speed: a striking observation on my PC!

Post 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)
Last edited by Dräc on Sat Oct 29, 2005 7:13 pm, edited 2 times in total.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

during the second run, (parts of) your code is still cached, hence the speed increase.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

Normally, the two codes are independent. No resource shared!
What do you mean?
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post 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).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

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

Post 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 ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

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

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Lep
New User
New User
Posts: 4
Joined: Fri Sep 09, 2005 9:53 pm

Post by Lep »

I tested it on Windows 98, running both windows at the same time and got values from 30-32 on both.
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post 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 ?
Lep
New User
New User
Posts: 4
Joined: Fri Sep 09, 2005 9:53 pm

Post by Lep »

P3 500mhz
Dräc
Enthusiast
Enthusiast
Posts: 150
Joined: Sat Oct 09, 2004 12:10 am
Location: Toulouse (France)
Contact:

Post by Dräc »

Aaaaarg! I’m dead! What is going wrong with my configuration ?…
Sub-Routine
User
User
Posts: 82
Joined: Tue May 03, 2005 2:51 am
Location: Wheeling, Illinois, USA
Contact:

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply