Try this:
First, save the following as "SetMemory.h"
And then give this a test run:
I added a CONST up top so you can compare speeds with _DISPLAY in use and not.
(Note, that's with the compiler settings checked for optimization, under the OPTIONS menu.)
First, save the following as "SetMemory.h"
Code: (Select All)
#include <algorithm>
#include <cstdint>
#include <cstdio>
inline void SetMemoryByte(uintptr_t dst, uint32_t elements, uint8_t value) {
std::fill(reinterpret_cast<uint8_t *>(dst),
reinterpret_cast<uint8_t *>(dst) + elements, value);
}
inline void SetMemoryInteger(uintptr_t dst, uint32_t elements, uint16_t value) {
std::fill(reinterpret_cast<uint16_t *>(dst),
reinterpret_cast<uint16_t *>(dst) + elements, value);
}
inline void SetMemoryLong(uintptr_t dst, uint32_t elements, uint32_t value) {
std::fill(reinterpret_cast<uint32_t *>(dst),
reinterpret_cast<uint32_t *>(dst) + elements, value);
}
And then give this a test run:
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)
CONST Display = 0
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
DIM CLSMTime AS DOUBLE
Image = _NEWIMAGE(320, 200, 32) ' create test image
SCREEN _NEWIMAGE(640, 480, 32) ' create graphics screen
'+------------------------+
'| CLS 3 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
IF Display THEN _DISPLAY
LOOP UNTIL TIMER(.001) - t1 >= 3 ' leave after 1 second
CLSTime = c ' total frames
'+-------------------------+
'| CLSI 3 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
IF Display THEN _DISPLAY
LOOP UNTIL TIMER(.001) - t1 >= 3 ' leave after 1 second
CLSITime = c ' total frames
'+-------------------------+
'| CLSM 3 second time test |
'+-------------------------+
c = 0 ' reset counter
t1 = TIMER(.001) ' start time
DO ' begin counted loop
c = c + 1 ' increment counter
CLSM RED, _DEST ' clear main screen red
CLSM CYAN, Image ' clear image cyan
IF Display THEN _DISPLAY
LOOP UNTIL TIMER(.001) - t1 >= 3 ' leave after 1 second
CLSMTime = c ' total frames
'+-----------------+
'| Display results |
'+-----------------+
_AUTODISPLAY
_PUTIMAGE (159, 139), Image ' place test image onto graphics screen
PRINT "3 Second Test"
PRINT "-------------"
PRINT "CLS Frames :"; CLSTime ' total frames for CLS
PRINT "CLSI Frames:"; CLSITime ' total frames for CLSI
PRINT "CLSM Franes:"; CLSMTime
DO: LOOP UNTIL _KEYDOWN(27)
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
' _____________________________________________________________________________
'/ \
SUB CLSM (bgColor AS _UNSIGNED LONG, ImageHandle AS LONG) ' CLSI |
' _________________________________________________________________________|____
'/ \
'| CLS Mem |
'| Note: does not support CLS methods |
'| |
'| bgColor : color used to clear the image |
'| ImageHandle: image to clear |
'\______________________________________________________________________________/
DECLARE LIBRARY "SetMemory"
SUB SetMemoryByte (BYVAL dst AS _UNSIGNED _OFFSET, BYVAL elements AS _UNSIGNED LONG, BYVAL value AS _UNSIGNED _BYTE)
SUB SetMemoryInteger (BYVAL dst AS _UNSIGNED _OFFSET, BYVAL elements AS _UNSIGNED LONG, BYVAL value AS _UNSIGNED INTEGER)
SUB SetMemoryLong (BYVAL dst AS _UNSIGNED _OFFSET, BYVAL elements AS _UNSIGNED LONG, BYVAL value AS _UNSIGNED LONG)
END DECLARE
DIM oDest AS _MEM
oDest = _MEMIMAGE(ImageHandle)
SetMemoryLong oDest.OFFSET, (_WIDTH(ImageHandle) * _HEIGHT(ImageHandle)), bgColor
END SUB
I added a CONST up top so you can compare speeds with _DISPLAY in use and not.
(Note, that's with the compiler settings checked for optimization, under the OPTIONS menu.)