1
2
Feb 25 2009, 4:00 pm
In response to Stupot
|
|
Actually, I've compared the bitwise shift operators with the multiplication operator (a few different numbers, as I was pretty sure this would affect it a little). In DM, they are slower than multiplying! Popisfizzy said that this is because BYOND stores numbers as floats, so it needs to convert the number to an int and back to perform the operation. I'm not sure about the other bitwise operators, but they don't have any counterparts.
|
In response to Jeff8500
|
|
Example please? I'm not quite sure what you mean Jeff x.x
|
In response to Spunky_Girl
|
|
Ints and floats are types of C++ variables. Floats can contain decimals (and larger numbers in general), and ints can't. Bitwise operations can only be called on ints. Therefore BYOND needs to convert the floats to ints to perform the operation, and then it needs to convert it back.
|
In response to Jeff8500
|
|
Oh okay. Thanks.
|
In response to Jeff8500
|
|
Jeff8500 wrote:
(...)In DM, they are slower than multiplying!(...) As this is very interesting (at least to me), could you provide us with the exact figures of your test? |
In response to Schnitzelnagler
|
|
The results varied depending on what you shifted by and what you multiplied with. Somewhere along the lines, shifting used about 0.07% and multiplying used 0.04% of the CPU. I think that was when I shifted by two and multiplied by four (10,000x), but I'll have to check.
EDIT: It appears that shifting uses about 0.04% of your CPU when used 10,000 times, which multiplying uses about 0.02% of your CPU. This was all performed on 1. |
In response to Jeff8500
|
|
That's... very minuscule lol o.o;
But I guess when you have a crap-load of calculations happening all at once for multiple instances, it builds up. |
In response to Spunky_Girl
|
|
Well, it's easier to think in terms of multiplication than in terms of bit-shifting most of the time anyway. The confusion comes in when people assume that bit-shifting is faster, which is true in assembler code. However, in BYOND if you were hitting a bottleneck with a lot of multiplications, bit shifting could not yield a faster computation; that might be useful to know, but since nobody writes number-crunching apps on BYOND, it's not really relevant. :-)
|
In response to PirateHead
|
|
Ah, okay. Useful info that tidbit is :)
|
In response to PirateHead
|
|
PirateHead wrote:
The confusion comes in when people assume that bit-shifting is faster, which is true in assembler code. :-) It's not a matter of assembly code or not, it's a matter of what the numbers are stored as, as stated earlier. For C++, bitwise calculations (when applicable) are faster when used with integers. Floating point numbers aren't stored in the same fashion as ints and therefore bit-wise calculations will either yield incorrect results or the floats will need to be converted into integers first, which adds more time than what would be saved. For more information on floats: http://steve.hollasch.net/cgindex/coding/ieeefloat.html |
In response to Stupot
|
|
Well, the notion of bit-shifting a float is a absurd on its face. No assembler or processor that I know of defines a bit-shift operator on float values, and if a compiler does then it's just doing the float->integer->float conversion which makes no sense in terms of efficiency.
|
1
2