publicclass Main { // Numbers have to be inlined for the bug to trigger: we cannot define this as a generic method // that takes e.g. 12 as a parameter. We can define some methods to test different cases. Each // method is the same as doing: // result = initial_value; // for (int i = start; i < end; ++i) { result += i * 10; } // return result; // As long as `end` is 5 or less
privatestaticint $noinline$nestedLoopCalculation_0_2_12() { int result = 12; for (int outer = 0; outer < 2; ++outer) { int first_inner; for (first_inner = 5; first_inner > outer; first_inner--) {} for (int second_inner = 0; second_inner < 10; second_inner++) {
result += first_inner;
}
} return result;
}
privatestaticint $noinline$nestedLoopCalculation_1_3_12() { int result = 12; for (int outer = 1; outer < 3; ++outer) { int first_inner; for (first_inner = 5; first_inner > outer; first_inner--) {} for (int second_inner = 0; second_inner < 10; second_inner++) {
result += first_inner;
}
} return result;
}
privatestaticint $noinline$nestedLoopCalculation_minus2_2_12() { int result = 12; for (int outer = -2; outer < 2; ++outer) { int first_inner; for (first_inner = 5; first_inner > outer; first_inner--) {} for (int second_inner = 0; second_inner < 10; second_inner++) {
result += first_inner;
}
} return result;
}
privatestaticint $noinline$nestedLoopCalculation_0_5_12() { int result = 12; for (int outer = 0; outer < 5; ++outer) { int first_inner; for (first_inner = 5; first_inner > outer; first_inner--) {} for (int second_inner = 0; second_inner < 10; second_inner++) {
result += first_inner;
}
} return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.