Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible CLS improvement
#12
(10-10-2023, 06:10 PM)TerryRitchie Wrote:
(10-10-2023, 05:30 PM)Jack Wrote: on my PC running Windows 11 the difference is 0.001
the time varies too much between runs to get a good estimate
On my system running Windows 7 Pro x64 I usually see a difference of between .02 and .03. Windows 11 has a lot going on under the hood (spying, tracking, telemetry, etc..) that is probably skewing the results. Sad
In all seriousness, I rewrote the mechanism to time the routines using frames because your system is probably much faster than the .001 resolution of TIMER.

However, using frames shows that CLS has the slight advantage??

I dunno. Either method of timing is so close though I doubt that it matters much.

Code: (Select All)
'
' CLS Image
'
' There is a very slight increase in performance using CLSI over CLS (not using this timing method).
' The reason I wrote CLS Image was to avoid having to change the
' destination to the image and then back again to the original image.
' The subroutine now handles that cleanly.
'
' Note that CLSI does not support CLS' methods (0 through 2).
'

CONST RED~& = _RGB32(255, 0, 0) '   define a few colors
CONST CYAN~& = _RGB32(0, 255, 255)

DIM Image AS LONG '                 test image
DIM c AS LONG '                     counter
DIM t1 AS DOUBLE '                  time start
DIM t2 AS DOUBLE '                  time end
DIM CLSTime AS DOUBLE '             CLS total time
DIM CLSITime AS DOUBLE '            CLSI total time

Image = _NEWIMAGE(320, 200, 32) '   create test image
SCREEN _NEWIMAGE(640, 480, 32) '    create graphics screen

'+------------------------+
'| CLS 1 second time test |
'+------------------------+

c = 0 '                             reset counter
t1 = TIMER(.001) '                  start time
DO '                                begin counted loop
    c = c + 1 '                     increment counter
    CLS , RED '                     clear main screen red
    _DEST Image '                   change write image to Image
    CLS , CYAN '                    clear image cyan
    _DEST 0 '                       change write image to SCREEN
LOOP UNTIL TIMER(.001) - t1 >= 1 '  leave after 1 second
CLSTime = c '                       total frames

'+-------------------------+
'| CLSI 1 second time test |
'+-------------------------+

c = 0 '                             reset counter
t1 = TIMER(.001) '                  start time
DO '                                begin counted loop
    c = c + 1 '                     increment counter
    CLSI RED, _DEST '               clear main screen red
    CLSI CYAN, Image '              clear image cyan
LOOP UNTIL TIMER(.001) - t1 >= 1 '  leave after 1 second
CLSITime = c '                      total frames

'+-----------------+
'| Display results |
'+-----------------+

_PUTIMAGE (159, 139), Image '       place test image onto graphics screen
PRINT "1 Second Test"
PRINT "-------------"
PRINT "CLS Frames :"; CLSTime '     total frames for CLS
PRINT "CLSI Frames:"; CLSITime '    total frames for CLSI
PRINT "Difference :"; CLSTime - CLSITime ' difference
SLEEP '                             wait for key press
SYSTEM '                            return to OS

' _____________________________________________________________________________
'/                                                                             \
SUB CLSI (bgColor AS _UNSIGNED LONG, ImageHandle AS LONG) '               CLSI |
    ' _________________________________________________________________________|____
    '/                                                                              \
    '| CLS Image                                                                    |
    '| Note: does not support CLS methods                                           |
    '|                                                                              |
    '| bgColor    : color used to clear the image                                   |
    '| ImageHandle: image to clear                                                  |
    '\______________________________________________________________________________/

    DIM oDest AS LONG ' calling destination

    oDest = _DEST '                                      save calling destination
    _DEST ImageHandle '                                  change write image
    LINE (0, 0)-(_WIDTH - 1, _HEIGHT - 1), bgColor, BF ' draw a box filled line
    _DEST oDest '                                        return to calling destination

END SUB
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Possible CLS improvement - by TerryRitchie - 10-09-2023, 04:35 PM
RE: Possible CLS improvement - by SMcNeill - 10-09-2023, 04:51 PM
RE: Possible CLS improvement - by TerryRitchie - 10-09-2023, 04:56 PM
RE: Possible CLS improvement - by James D Jarvis - 10-09-2023, 05:36 PM
RE: Possible CLS improvement - by TerryRitchie - 10-09-2023, 06:23 PM
RE: Possible CLS improvement - by SMcNeill - 10-09-2023, 06:36 PM
RE: Possible CLS improvement - by TerryRitchie - 10-09-2023, 09:33 PM
RE: Possible CLS improvement - by mnrvovrfc - 10-10-2023, 02:53 PM
RE: Possible CLS improvement - by TerryRitchie - 10-10-2023, 05:03 PM
RE: Possible CLS improvement - by Jack - 10-10-2023, 05:30 PM
RE: Possible CLS improvement - by TerryRitchie - 10-10-2023, 06:10 PM
RE: Possible CLS improvement - by TerryRitchie - 10-10-2023, 07:30 PM
RE: Possible CLS improvement - by SMcNeill - 10-11-2023, 12:18 AM
RE: Possible CLS improvement - by SMcNeill - 10-11-2023, 02:20 AM
RE: Possible CLS improvement - by mnrvovrfc - 10-11-2023, 03:33 AM



Users browsing this thread: 3 Guest(s)