Files
java-core-examples/bufferedreader/output/03-heap.txt
T

23 lines
1.3 KiB
Plaintext

$ java -Xmx64m LineCount reader big.log
reader lines=9,623,347 chars=990,376,717 time=1,288 ms gc=37 collections / 31 ms (-Xmx64 MB)
$ java -Xmx64m LineCount scanner big.log
scanner lines=9,623,347 chars=990,376,717 time=6,233 ms gc=140 collections / 116 ms (-Xmx64 MB)
$ java -Xmx64m LineCount lines big.log
lines lines=9,623,347 chars=990,376,717 time=1,179 ms gc=37 collections / 32 ms (-Xmx64 MB)
$ java -Xmx64m LineCount readAllLines big.log
readAllLines OutOfMemoryError: Java heap space (-Xmx64 MB)
How much heap does readAllLines need for this file?
$ java -Xmx1g LineCount readAllLines big.log
readAllLines OutOfMemoryError: Java heap space (-Xmx1024 MB)
$ java -Xmx2g LineCount readAllLines big.log
readAllLines lines=9,623,347 chars=990,376,717 time=2,872 ms gc=24 collections / 922 ms (-Xmx2048 MB)
$ java -Xmx3g LineCount readAllLines big.log
readAllLines lines=9,623,347 chars=990,376,717 time=2,729 ms gc=23 collections / 949 ms (-Xmx3072 MB)
$ java -Xmx4g LineCount readAllLines big.log
readAllLines lines=9,623,347 chars=990,376,717 time=2,862 ms gc=23 collections / 905 ms (-Xmx4096 MB)
And the streaming reader at a tiny heap:
$ java -Xmx16m LineCount reader big.log
reader lines=9,623,347 chars=990,376,717 time=1,347 ms gc=171 collections / 101 ms (-Xmx16 MB)