C optimization question -
I think the fastest way is to write some code I have a loop that connects in ints is. The loop will be executed several times, and so I have tried to compare it to check whether any operx is zero, so they should not be added as they are:
If (work1 == 0) {if (work2 == 0) tempAnswer = toCarry; Else tempAnswer = work2 + toCarry; } And if (work2 == 0) tempAnswer = work1 + toCarry; Else tempAnswer = work1 + work2 + toCarry;
I believe that if the nested is already an optimization on the top, then it & amp; Amp; Amp; Amp; Amp; Amp; And compared with writing a series of comparisons, because I (task 1 == 0)
more than once.
Unfortunately, I will not be able to say how many times the work 1 and work2 are zero, then assume that it can be balanced distribution of every possible outcome of the IF statement.
So, in that light, the above code is more than just written tempAnswer = work1 + work2 + toCarry
or because of all comparisons, there are many drages?
Thanks
This is nonsense.
- Comparing two integers when adding only two integers
- One branch is too much, many more (many, at large, of course (see comments), CPU )
-
On more modern architecture, the barriers are accessing value from memory, so this plan is still not helping where it is necessary.
Also, think about this rational - why do you value zero as a value in the form of a special zero? Why not check for one too, and use
tempAnswer ++
? When you consider all possibilities, you can see that this is a futile exercise.
Comments
Post a Comment