Are there any cons of using scalacl plugin?
I am planning to use scala in my project. I have written a little bit of code in scala to see its time of execution.
(1 to 1000000).map(1 + _).sum
1. Without plugin
is compiled to something like this:
BoxesRunTime.unboxToInt(((TraversableOnce)Predef..MODULE$.intWrapper(1).to(1000000).map(new MyScala..anonfun.1(), IndexedSeq..MODULE$.canBuildFrom())).sum(Numeric.IntIsIntegral..MODULE$));
and run in about 375 ms
2. With scalacl plugin
int i = 1;
int j = 1000000;
int k = j;
int m = i;
for (VectorBuilder localVectorBuilder = new VectorBuilder(); m <= k;) {
int n = m;
localVectorBuilder.$plus$eq(BoxesRunTime.boxToInteger(1 + n));
m += 1;
}
int a = BoxesRunTime.unboxToInt(localVectorBuilder.result().sum(Numeric.IntIsIntegral..MODULE$));
259 ms
Range#sum
is now optimized in trunk and runs in constant timeO(n)
instead of linearO(n)
. Algorithmic improvements are most of the time preferable. – Interurban