Computes, N times, (S i | 0 � i � 999 : (-1)i+1 � i) - 500. This is done the hard way -- coding it as 0 + 1 - 2 + 3... This tests your compiler's ability to do simple constant folding. The optimization should cause little penalty in compile time, but cause run time to decrease greatly.
Source: [fold.im fold.cpp
Fold.java]
Input: N=10,000,000
Output: 0
C++ | 0.2 | ![]() |
Java | 0.3 | |
B | 0.67 | |
C | 0.75 | |
D | 0.84 | |
G | 0.86 | |
E | 0.88 | |
H | 1.19 |