Hi.

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 variables) * uses an Iterator<Integer> (thus there are "int" <-> "Integer" conversions)

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?


Regards,
Gilles



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to