Any significant performance improvement by using bitwise operators instead of plain int sums in C#? -
I started working with C # a few weeks ago, and now I am in a situation where I have "different in bit algorithm Set the flag to handle matters. "I have two options like this:
enum relative positioning {LEFT = 0, right = 1, dot = 2, top = 3, front = 4 , Back = 5} pause = ((eye.X & lt; minCorner.X? 1: 0) & lt; (int) relative positioning. LEFT) + ((Eyes XX.MaxConverter.x? 1 : 0) & lt; relay (int) Tipting rifle) + ((Y.Y.L. L. Min Corner. Y? 1: 0) & lt; (Int) Relative Positioning. Bottom) + ((IY & G; Maxcor. Y? 1 : 0) & lt; & lt; (int) relative pausing top) + ((Z. Z. Lieutenant; Minkoner.Z1: 0) & lt; & lt; (int) relative position. Font) + ((Eyes Z. Maxcorder.Z1: 0) & lt; & lt; (Int) relativity. BAP);
or:
enum relative positioning {LEFT = 1, right = 2, dot = 4, top = 8, front = 16, back = 32 } If (Eye X.Lt; minCorner.X) {pos + = (int) RelativePositioning.LEFT; } If (eye.X> maxCorner.X) {pos + = (int) relative positioning. Right; } If (Eye Wy and Lieutenant; Mincoorner Y) {POS + = (Int) Relative Positioning. Botam; } If (eye.Y & gt; maxCorner.Y) {pos + = (int) relative potion. TOP; } If (eye.Z & gt; maxCorner.Z) {pos + = (int) RelativePositioning.FRONT; } If (Eye Jade & Lieutenant; Mincorner .Z) {Pose + = (Int) Relativity. Back; }
I could use something as ((X. X & gt; maxCorner.X) , but The underlying casting is not allowed from C # Bool was sufficiently equal to int and ternary operator. My question is now: Is there any improvement in using the first version of the second edition?
Thanks
Tomoso
inline if
The operator (?
, :
) will generate approximately the same IL standard if
list is in the second example you will see here that the only difference is that The processor is working, and I can bet that the code is faster than ADD
SHL
.
To add results any time you are going, I choose the option for another example (Plus makes it easy to read).
edit
I just tested IL in both instances, and after that I went against what I said.
The first example IL makes (34 lines short) is very low, so you really need to run a demonstration test to determine what is it fast.
Comments
Post a Comment