Suppose I have a naive factorial function:
import java.util.stream.LongStream; public class FactorialTest { static long factorial(long n, boolean parallel) { return (parallel ? LongStream.range(1, n).parallel() : LongStream.range(1, n)) .reduce(1, (l, m) -> l * m); } public static void main(String[] args) { System.out.println(factorial(10, true)); } } I have a feeling that multi-threaded reduction is still faster than single-threaded even on a single-logical-core machine. How can I test this with the stream API or work around it?