4 ms·
> We don't really know how much memory Java needs on this benchmark. The JVM will use as much memory as you give it. ## /usr/bin/time java -Xmx48M -cp build/
by nybble41 5y ago
> We don't really know how much memory Java needs on this benchmark. The JVM will use as much memory as you give it.
## /usr/bin/time java -Xmx48M -cp build/java Main2 ...
90.14user 1.36system 1:29.07elapsed 102%CPU (0avgtext+0avgdata 147396maxresident)k
0inputs+288outputs (36major+37251minor)pagefaults 0swaps
## /usr/bin/time ./phone_encoder ...
29.91user 0.08system 0:30.01elapsed 99%CPU (0avgtext+0avgdata 16704maxresident)k
0inputs+0outputs (0major+4940minor)pagefaults 0swaps
I used the default dictionary, and the input file with 10 million numbers was generated with "java -cp build/util util.GeneratePhoneNumbers 10000000 true".
So… I gave the Java version over 2.25x as much heap memory as the maximum resident size of the Rust version (./phone_encoder), but it actually used almost 100 MB more than that, and still took 3x as long to finish. I also tried with -Xmx40M:
## /usr/bin/time java -Xmx40M -cp build/java Main2 ...
270.91user 4.30system 1:40.23elapsed 274%CPU (0avgtext+0avgdata 150588maxresident)k
0inputs+480outputs (60major+35615minor)pagefaults 0swaps
Here we start to see a substantial performance hit due to excessive GC, and maximum resident size has actually increased slightly. Elapsed time is only about 11 seconds longer than with -Xmx48M due to parallelism, but total CPU time (user + system) has ballooned to 274 seconds—nine times the Rust version.
This is comparing against my optimized Rust implementation[0], not the one from the article. It employs the same algorithm but eschews heap allocation. I used /usr/bin/time rather than the included benchmark_runner because benchmark_runner makes use of what appear to be MacOS (Darwin) APIs (libproc::libproc::pid_rusage) to measure memory use and consequently doesn't build on my Linux system with this functionality intact.
[0] https://github.com/nybble41/prechelt-phone-number-encoding https://github.com/nybble41/prechelt-phone-number-encoding
- native_samples 5y agoWell, that answers that then!