Does anyone have any comments on which of these pieces of code will run more efficiently?
In these code examples, [tt]check[/tt] is a variable of type [tt]bool[/tt] (it is an actual variable, not an expression that is reevaluated each time the [tt]if()[/tt] statement is run), and [tt]i[/tt] and [tt]N[/tt] are unsigned ints.
and
I'd be inclined to go with the former but I'm interested in what more experienced people have to say. Many thanks!
In these code examples, [tt]check[/tt] is a variable of type [tt]bool[/tt] (it is an actual variable, not an expression that is reevaluated each time the [tt]if()[/tt] statement is run), and [tt]i[/tt] and [tt]N[/tt] are unsigned ints.
Code:
if(check) {
for(i=0;i<N;++i) {
function_1();
function_2();
}
} else {
for(i=0;i<N;++i)
function_1();
}
and
Code:
for(i=0;i<N;++i) {
function_1();
if(check)
function_2();
}
I'd be inclined to go with the former but I'm interested in what more experienced people have to say. Many thanks!