Java 8 Stream string of map calls versus combining into one -
when using java 8 stream api, there benefit combining multiple map calls one, or not affect performance?
for example:
stream.map(someclass::operation1).map(someclass::operation2); versus
stream.map(o -> o.operation1().operation2());
the performance overhead here negligible business-logic operations. have 2 additional method calls in pipeline (which may not inlined jit-compiler in real application). have longer call stack (by 1 frame), if have exception inside stream operation, creation little bit slower. these things might significant if stream performs low-level operations simple math. of real problems have bigger computational cost, relative performance drop unlikely noticeable. , if perform simple math , need performance, it's better stick plain old for loops instead. use version find more readable , not perform premature optimization.
Comments
Post a Comment