You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gilles <gi...@harfang.homelinux.org> on 2016/05/17 11:38:13 UTC

[Math] IntegerSequence

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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org