Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Arkanoid: "Sleep 10" to reduce CPU usage

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Arkanoid: "Sleep 10" to reduce CPU usage

    This is about a post at http://community.thinbasic.com/index...13310#msg13310
    _________________________________________________
    Petr,

    I'm not sure SLEEP 10 is the solution to reduce CPU usage especially on fast processors having multy core.
    On those CPU SLEEP 10 add a visible stepping and does not reduce any CPU usage.

    The method I think is best is to pass a time slice to Windows to manage events. And this is done using DOEVENTS or similar methods. But this is already done in thnBasic Core engine every time a WHILE keyword is encountered. To prove that, when you execute a UI script having a main WHILE/WEND loop, CPU is almost at zero even if thinBasic engine is parsing continuously message pump of the script.

    I think you have to check inside TBGL module and see if after creating TBGL window you have a CALLBACK fucntion that handle the windows events. If you have, try to check if that callback is taking some time. If you have no CALLBACK for TBGL windo, create one that does not handle eny event but just pass them to the standard window function.

    I will investigate more on this.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    Hi Eros,

    the window is created old good Petzold way, so pure Win32 window with callback WndProc.
    It is executed approximately various number of times in second on my PC, but it does almost nothing

    Processed messages are:
    %WM_CREATE
    %WM_ERASEBKGND
    %WM_MOUSEWHEEL
    %WM_SIZE
    %WM_MOVE
    %WM_CLOSE
    %WM_DESTROY
    %WM_SYSCOMMAND

    So as you see, many of them get processed just once.
    The whole WndProc take almost unmeasurable time, and is executed approximately few times a second in ideal case.


    Petr

    P.S. Following script shows 99% CPU on AMD Sempron 3400+ 64bit
    [code=thinbasic]
    while 1
    wend
    [/code]
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    What value do you return in FUNCTION on %WM_ERASEBKGND notification message?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    Hi Eros,

    FUNCTION = %TRUE

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    OK thanks, Return code not zero means you handle the event so ok.

    Quote Originally Posted by Psch
    P.S. Following script shows 99% CPU on AMD Sempron 3400+ 64bit
    [code=thinbasic]
    while 1
    wend
    [/code]
    That's because it is not using UI module.
    I'm not on my computer so I cannot test right now but if it goes almost 100% CPU there must be something from my side.
    Thanks I will check soon.

    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    I tried to use UI:
    uses "UI"
    while 1
    wend
    And this way I get from 45 to 55%


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    ATTENTION: use attached thinCore only for testing !!!!_________________________________________________
    Petr,

    please test attached thinCore.dll and see if it makes any difference.
    Do not use any SLEEP or add any UI module in order not to influence your tests.

    Thanks a lot
    Eros


    PS: File removed.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    How did you do that ;D

    Seems to work ok! In some TBGL scripts it seems the FPS is suddenly limited to very stable 64 FPS or so, but in others ( TopDown, tbglBenchmark ) I get the same as before, so up to 850 FPS. Seems quite ok!

    But CPU hogging is at very low level, mostly reported as 0


    Thanks thanks!,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    What about CPU usage?
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Arkanoid: "Sleep 10" to reduce CPU usage

    Mostly 0%,

    so perfect!
    The "worst" was about 2%


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 1 of 2 12 LastLast

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •