Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shifting versus Mutliplying
#2
Functionally speaking a regular `* 4` with a constant 4 should not be faster than `_SHL`. The C++ compiler is smart enough to simply use a left shift to implement multiplication when it's a power of two, you don't have to use `_SHL`. The benefits come when the shift value is not a constant, in that case the compiler cannot optimize the multiplication.

For your test code, I think the general issue is that `TIMER(.001)` is significantly more expensive than the single shift you're doing, I would expect any kind of fluctuation to be more related to `TIMER(.001)`s performance than anything else. Instead of looping for a set amount of time, you should instead try performing a set number of `_SHL` or `* 4` commands (ex. 1 million of them) and then measure how long it takes to execute all of them by calling `TIMER(.001)` at the start and end.

(03-11-2024, 03:36 AM)TerryRitchie Wrote: 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.
I have not heard about that, but I'll keep an eye out, that sounds odd.
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: 5 Guest(s)