Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shifting versus Mutliplying
#4
Ok, I reworked the code and multiplying is definitely faster. Thanks for the insight DSMan195276.

Code: (Select All)
DIM x AS INTEGER
DIM y AS INTEGER
DIM i AS LONG
DIM t AS DOUBLE
DIM t1 AS DOUBLE
DIM t2 AS DOUBLE

x = 4
DO
    i = 0
    t = TIMER(.001)
    DO
        y = x * 4
        i = i + 1
    LOOP UNTIL i = 1000000000 ' a billion times
    t1 = TIMER(.001) - t

    i = 0
    t = TIMER(.001)
    DO
        y = _SHL(x, 2)
        i = i + 1
    LOOP UNTIL i = 1000000000
    t2 = TIMER(.001) - t

    BEEP
    CLS
    PRINT
    PRINT USING " #.### --> Multiplying"; t1
    PRINT USING " #.### --> Shiting left"; t2

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


Messages In This Thread
Shifting versus Mutliplying - by TerryRitchie - 03-11-2024, 03:36 AM
RE: Shifting versus Mutliplying - by DSMan195276 - 03-11-2024, 03:57 AM
RE: Shifting versus Mutliplying - by TerryRitchie - 03-11-2024, 04:19 AM
RE: Shifting versus Mutliplying - by TerryRitchie - 03-11-2024, 04:34 AM
RE: Shifting versus Mutliplying - by a740g - 03-11-2024, 05:16 AM
RE: Shifting versus Mutliplying - by DSMan195276 - 03-11-2024, 06:21 AM
RE: Shifting versus Mutliplying - by Kernelpanic - 03-11-2024, 12:28 PM
RE: Shifting versus Mutliplying - by mcalkins - 05-05-2024, 11:51 PM



Users browsing this thread: 3 Guest(s)