commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <>
Subject [Math] IntegerSequence
Date Tue, 17 May 2016 11:38:13 GMT

Quoting from another thread:

> I have a related story. There is a class in commons-math 4.0 called
> IntegerRange. Stylistically I much prefer Iterating over such a range 
> than
> C style loops and was ready to convert. However I found it many times
> slower, at least in not terribly rigorous home micro-benchmarking.
> Any good reason why this should be so?

It is definitely doing more than just increment an "int" counter:
  * creates an instance of "Incrementor" (thus initializing several 
  * uses an Iterator<Integer> (thus there are "int" <-> "Integer" 

It is clear that when the computation inside the loop takes about
the same time as an integer addition, any other way to iterate will
be slower.

"IntegerSequence" was not an attempt to be a replacement of "foreach"
but only a way to make a callback at loop exhaustion.

That said, and looking back at the code, I have a design question.
Assuming that ultimate performance is not an issue (since we agree
that for that the usual loop constructs are better), I was wondering
about changing the "int" into "long" values (so that a "Range" could
be much larger).

Any objection?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message