03-11-2024, 03:36 AM
(This post was last modified: 03-11-2024, 03:43 AM by TerryRitchie.)
In my quest learning the _MEM related commands I'm also looking for the fastest possible ways to do things.
When working with image memory blocks many times you need to multiply by 4 to calculate offsets to pixel locations. Instead of multiplying by 4 I thought perhaps shifting left by 2 would be faster and still achieve the same result. So I wrote a little speed test program (below) to prove this out.
When the program is first run the very first loop will sometimes show multiplying is faster than shifting, but then subsequent loops show shifting is faster.
Now here is the really weird part, REM the SLEEP 3 line in the code below and multiplying is always faster ???
Any idea what is causing this? I'm using QB64PE version 3.12.0. (Update: I just ran the code in version 3.11.0 with the same results)
Also, has anyone else noticed that the 3.12.0 IDE flickers occasionally when not using it (not the active window)? As I am writing this text into the forum it's flickering now and then. This also happens when I run code and press keys while the code is running, the IDE flickers in the background.
When working with image memory blocks many times you need to multiply by 4 to calculate offsets to pixel locations. Instead of multiplying by 4 I thought perhaps shifting left by 2 would be faster and still achieve the same result. So I wrote a little speed test program (below) to prove this out.
When the program is first run the very first loop will sometimes show multiplying is faster than shifting, but then subsequent loops show shifting is faster.
Now here is the really weird part, REM the SLEEP 3 line in the code below and multiplying is always faster ???
Any idea what is causing this? I'm using QB64PE version 3.12.0. (Update: I just ran the code in version 3.11.0 with the same results)
Also, has anyone else noticed that the 3.12.0 IDE flickers occasionally when not using it (not the active window)? As I am writing this text into the forum it's flickering now and then. This also happens when I run code and press keys while the code is running, the IDE flickers in the background.
Code: (Select All)
DIM x AS INTEGER
DIM y AS INTEGER
DIM i AS LONG
DIM t AS DOUBLE
DIM f1 AS LONG
DIM f2 AS LONG
DIM h AS DOUBLE
DIM l AS DOUBLE
DIM p AS DOUBLE
x = 4
DO
i = 0
t = TIMER(.001)
DO
y = x * 4
i = i + 1
LOOP UNTIL TIMER(.001) - t >= 1
f1 = i
i = 0
t = TIMER(.001)
DO
y = _SHL(x, 2)
i = i + 1
LOOP UNTIL TIMER(.001) - t >= 1
f2 = i
p = (f2 - f1) / f1 * 100 ' calculate percentage
IF p > h THEN h = p
IF l = 0 THEN l = p
IF p < l THEN l = p
CLS
PRINT
PRINT f1; "--> Multiplying"
PRINT f2; "--> Shifing left"
PRINT
PRINT f2 - f1; "--> Additional calculations using shifting"
PRINT USING " ##.##% --> Increase"; p
PRINT
PRINT USING " ##.##% --> Lowest seen"; l
PRINT USING " ##.##% --> Highest seen"; h
' Rem the following line for negative results ???
SLEEP 3
LOOP