Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

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

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

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

    You will not bealive it.

    I changed my Power Basic IDLE message pump (executed during WHILE/WEND operations) from:
    [code=thinbasic]
    MACRO NewDoEvents
    MacroTemp nde_Msg
    Dim nde_Msg As TagMsg
    If PeekMessage(nde_Msg, %Null, 0, 0, %PM_REMOVE) Then
    TranslateMessage nde_Msg
    DispatchMessage nde_Msg
    End If
    END MACRO

    [/code]

    to

    [code=thinbasic]
    MACRO NewDoEvents
    'GLOBAL nde_Msg AS TagMsg
    MacroTemp nde_Msg
    Dim nde_Msg As TagMsg
    If PeekMessage(nde_Msg, %Null, 0, 0, %PM_REMOVE) <> 0& Then
    If nde_Msg.message = %WM_QUIT Then
    Else
    TranslateMessage nde_Msg
    DispatchMessage nde_Msg
    End If
    End If
    END MACRO
    [/code]

    I think the change that effect CPU is from:
    [code=thinbasic] If PeekMessage(nde_Msg, %Null, 0, 0, %PM_REMOVE) Then[/code]
    to
    [code=thinbasic] If PeekMessage(nde_Msg, %Null, 0, 0, %PM_REMOVE) <> 0& Then[/code]

    I will investigate further about 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. #12
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

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

    Incredible ,


    how did you found that ... I have no idea
    But fact is that it works!


    Perfect,
    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

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

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

    I Google http://www.google.com/search?hl=en&q=apisleep+function
    And on the second link reported by Google I found this post: http://www.powerbasic.com/support/pb...ad.php?t=11924
    In there Michael Ritter reported a loop very similar to mine but with "<> 0&" boolean test. I tried and voilla, the magic.
    _________________________________________________

    On my Core Duo, CPU usage drop from fixed 50% (mainly one processor always 100% CPU) to 15-25 % variable CPU usage.

    I confirm the effect is done by the test
    <> 0&
    instead of not logic comparison test.

    I need some more confirmations because I have a lot of boolean tests made with just: IF variable THEN
    Worth and investigation.

    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

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

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

    I thought those tests are 100% equivalent,

    good to know that they are not!
    I have to go offline now or I will become zombie, but tommorow I will do some benchmarks ... very interesting.


    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. #15
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

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

    Hold on.

    I would like to give a kick in my back. I introduced a big mistake in the posted thinCore.dll version (now removed).
    Reduction of CPU usage was due to a time slice I reserved to the OS adding an internal looper I left by mistake.
    But with this looper, WHILE loops are too much slow.

    I'm reconsidering the entire matter.
    Maybe a sleep somewhere or better a new keyword that give some time to the OS is better.

    Sorry for the above ... illusion.
    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. #16
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

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

    I think I've got a good compromise.

    Instead of adding an internal SLEEP that would influence all scripts and (worst) it would be something "imposed" by the engine, I've modified DOEVENTS keyword in such a way that, if executed, it will give some time slice to the OS reducing CPU usage.

    So, download attached file and to see results, just add a DOEVENTS inside the main loop of the script or where you think it would be better to give time to CPU.

    Regards
    Eros
    Attached Files Attached Files
    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

  7. #17
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

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

    Hi Eros,

    I tried to use it like:
    [code=thinbasic]
    while tbgl_IsWindow(hWnd)
    doevents
    ...
    wend
    [/code]

    ... and it seems to work very nicely. Even with this "slowdowner" it is possible to reach framerates exceeding refreshrate of LCD while CPU is at nice 0-10%. Good job done, no need for kicking yourself


    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 2 of 2 FirstFirst 12

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
  •