Boolean Optimization
-
I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax
If (complicated boolean statement)
{
form.attribute = true;
}
else
{
form.attribute = false;
}I was wondering whether using something like this would make any difference
form.attribute = complicated boolean statement.
Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?
-
I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax
If (complicated boolean statement)
{
form.attribute = true;
}
else
{
form.attribute = false;
}I was wondering whether using something like this would make any difference
form.attribute = complicated boolean statement.
Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?
-
I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet). Here's the common syntax
If (complicated boolean statement)
{
form.attribute = true;
}
else
{
form.attribute = false;
}I was wondering whether using something like this would make any difference
form.attribute = complicated boolean statement.
Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?
The difference in performance is so very small that it's more a matter of taste and style. The second code is a bit more efficient, mainly because it doesn't contain a jump. If you only run the code a hundred times though, the difference in execution time is so small that it's not even possible to measure. --- b { font-weight: normal; }