Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 22151

Are bit or integer ops faster?

$
0
0
I'm making a function called RGBtoColor for converting color components to color number. I know the RGB() function already exists, but as with PSET, it is slow because RGB performs internal checks, and then tries to coerce the input to fit the actual numbers. For example, if it is greater than 255, it automaticaly converts it to 255. But if my numbers are already valid 8bit numbers, this checking just slows it down. So that's why I'm making my own function. But I need to know, which is faster, bitwise or integer operations.

My function will either end up saying
Code:

RGBtoColor = Red Or (Green * &H100&) Or (Blue * &H10000)
or it will end up saying

Code:

RGBtoColor = Red + Green * &H100& + Blue * &H10000
I want to know which will be faster.
I know that since VB can use "OR" for either logical or bitwise ops (unlike in C where | is bitwise and || is logical "or"), this means it has to run internal checks to see if the input will need bitwise or logical ops, which slows it down. But by how much? Is OR still faster than +, or is + actually faster than OR in VB due to OR's internal checking the data type (bitwise or logical) in VB (even though in C | is much faster than +)?

Viewing all articles
Browse latest Browse all 22151

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>