I'm currently learning Java as well as FP & Lazarus and was curious about the performance of Java compared to FP so thought I'd compare the times to find 100,000 primes. Code for FP:
Now the Java code (using version 1.8 of the JRE)
for(int i = 1; i < limit; i++)
Open your eyes, the bigger, the wider you can !!
After a while you'll see something funny...
oops. It makes very little difference to the results though.
halstead complexity for Pascal:
for, :=, to: 3 operators.
i, 1 , limit: 3 operands
halstead complexity for Java:
for, = , <, ++: 4 operators
i, 1, limit: 3 operands
Statistically speaking the Pascal
for in this case is less error prone.
But let's take a real case:
for this case,
for, :=, to, - : 4 operators.
for this case,
i, 0 , LiMIT, 1: 4 operands.
for(int i = 0; i < limit; i++)
for this case,
for, =, < , ++: 4 operators too.
for this case,
0, i limit: 3 operands
Is it really more simple ?
When we remove the error we have Pascal more complex for a
for.