Java VS Python benchmarks

Current benchmark data was generated on Fri May 20 2022, full log can be found HERE

CONTRIBUTIONS are WELCOME!

[x86_64][2 cores] Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz (Model 106)

* -m in a file name stands for multi-threading or multi-processing

* -i in a file name stands for direct intrinsics usage. (Usage of simd intrinsics via libraries is not counted)

* -ffi in a file name stands for non-stdlib FFI usage

* (You may find time < time(user) + time(sys) for some non-parallelized programs, the overhead is from GC or JIT compiler, which are allowed to take advantage of multi-cores as that's more close to real-world scenarios.)

binarytrees

Input: 18

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 696ms 2.2ms 409.6MB 713ms 83ms openjdk 19
java 2.java 732ms 12ms 407.3MB 713ms 120ms openjdk 18.0.1
java 2.java 1014ms 30ms 680.5MB 813ms 113ms graal/jvm 17.0.3
java 2.java 1293ms 8.5ms 1082.9MB 893ms 617ms openjdk/zgc 18.0.1
python 1.py 1667ms 61ms 273.7MB 1530ms 110ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 128ms 2.2ms 82.9MB 83ms 20ms pypy 3.8.13
java 2.java 165ms 4.3ms 107.3MB 167ms 37ms openjdk 19
java 2.java 170ms 6.4ms 107.5MB 173ms 20ms openjdk 18.0.1
java 2.java 296ms 1.4ms 243.7MB 183ms 150ms openjdk/zgc 18.0.1
java 2.java 495ms 4.1ms 170.5MB 243ms 27ms graal/jvm 17.0.3
python 1.py 641ms 4.3ms 12.3MB 610ms 13ms pyston 3.8.12
python 1.py 1532ms 2.7ms 11.8MB 1517ms 0ms cpython 3.10.4

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 760ms 90ms 208.5MB 1317ms 83ms openjdk 18.0.1
python 1.py 833ms 2.0ms 87.8MB 790ms 30ms pypy 3.8.13
java 1-m.java 933ms 37ms 465.4MB 1367ms 287ms openjdk/zgc 18.0.1
java 1-m.java 960ms 60ms 203.4MB 1720ms 73ms openjdk 19
java 1.java 1076ms 28ms 279.7MB 1337ms 93ms graal/jvm 17.0.3
python 1.py 2857ms 0.4ms 10.0MB 2843ms 0ms pyston 3.8.12
python 1.py 2859ms 0.7ms 9.3MB 2843ms 0ms cpython 3.10.4

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 218ms 1.9ms 81.6MB 183ms 20ms pypy 3.8.13
java 1-m.java 439ms 25ms 116.5MB 747ms 40ms openjdk 19
java 1-m.java 450ms 68ms 131.1MB 740ms 43ms openjdk 18.0.1
python 1.py 495ms 1.8ms 9.2MB 480ms 0ms pyston 3.8.12
python 1.py 504ms 1.7ms 8.5MB 490ms 0ms cpython 3.10.4
java 1-m.java 522ms 30ms 213.8MB 750ms 147ms openjdk/zgc 18.0.1
java 1.java 718ms 6.1ms 187.5MB 653ms 57ms graal/jvm 17.0.3

fannkuch-redux

Input: 11

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 1694ms 12ms 115.5MB 3200ms 47ms graal/jvm 17.0.3
java 1-m.java 1739ms 18ms 40.9MB 3257ms 50ms openjdk/zgc 18.0.1
java 1-m.java 1764ms 64ms 40.9MB 3373ms 13ms openjdk 18.0.1
java 1-m.java 1777ms 17ms 41.6MB 3387ms 23ms openjdk 19

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1-m.java 270ms 8.0ms 39.6MB 433ms 27ms openjdk 19
java 1-m.java 274ms 9.9ms 40.7MB 453ms 10ms openjdk 18.0.1
java 1-m.java 302ms 5.9ms 40.7MB 427ms 53ms openjdk/zgc 18.0.1
java 1.java 590ms 20ms 98.1MB 440ms 30ms graal/jvm 17.0.3

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 506ms 1.2ms 42.0MB 553ms 20ms openjdk 18.0.1
java 4.java 515ms 4.6ms 41.1MB 577ms 13ms openjdk 19
java 4.java 543ms 3.4ms 38.8MB 560ms 53ms openjdk/zgc 18.0.1
java 4.java 930ms 2.1ms 126.2MB 910ms 47ms graal/jvm 17.0.3
python 1.py 2691ms 81ms 90.8MB 2643ms 30ms pypy 3.8.13
python 5-m.py 3357ms 14ms 12.9MB 4937ms 1013ms pyston 3.8.12
python 5-m.py 3998ms 20ms 85.2MB 4463ms 930ms pypy 3.8.13
python 1.py 4467ms 32ms 8.2MB 4447ms 3ms pyston 3.8.12
python 5-m.py 4473ms 26ms 12.1MB 6287ms 1063ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 4.java 141ms 5.7ms 39.0MB 170ms 7ms openjdk 18.0.1
java 4.java 145ms 4.3ms 39.1MB 167ms 13ms openjdk 19
java 4.java 181ms 3.0ms 40.2MB 170ms 47ms openjdk/zgc 18.0.1
python 1.py 347ms 5.0ms 81.5MB 320ms 13ms pypy 3.8.13
python 5-m.py 408ms 6.5ms 12.9MB 537ms 130ms pyston 3.8.12
python 1.py 460ms 2.0ms 8.2MB 447ms 0ms pyston 3.8.12
java 4.java 464ms 4.5ms 89.8MB 187ms 23ms graal/jvm 17.0.3
python 5-m.py 522ms 3.8ms 12.0MB 670ms 147ms cpython 3.10.4
python 1.py 732ms 8.2ms 7.8MB 717ms 0ms cpython 3.10.4
python 5-m.py 813ms 7.3ms 85.3MB 900ms 443ms pypy 3.8.13

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 14ms 1.1ms 7.6MB 10ms 0ms pyston 3.8.12
python 1.py 15ms 0.6ms 7.5MB 10ms 0ms cpython 3.10.4
python 1.py 34ms 1.1ms 53.6MB 10ms 10ms pypy 3.8.13
java 1.java 71ms 3.3ms 59.7MB 64ms 14ms graal/jvm 17.0.3
java 1.java 75ms 4.6ms 38.7MB 76ms 6ms openjdk 18.0.1
java 1.java 78ms 3.9ms 38.4MB 76ms 6ms openjdk 19
java 1.java 115ms 2.8ms 38.3MB 76ms 52ms openjdk/zgc 18.0.1

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3-m.java 1452ms 20ms 113.0MB 2687ms 40ms openjdk 19
java 3-m.java 1455ms 10ms 113.4MB 2647ms 47ms openjdk 18.0.1
java 3-m.java 1515ms 56ms 197.1MB 2773ms 63ms graal/jvm 17.0.3
java 3-m.java 2013ms 36ms 174.4MB 3573ms 137ms openjdk/zgc 18.0.1
python 3-m.py 3674ms 52ms 204.5MB 6457ms 323ms pypy 3.8.13
python 3.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 3.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 3-m.java 447ms 47ms 83.3MB 730ms 33ms openjdk 18.0.1
java 3-m.java 484ms 12ms 95.1MB 833ms 30ms openjdk 19
java 3-m.java 497ms 47ms 97.6MB 767ms 77ms openjdk/zgc 18.0.1
python 3-m.py 539ms 4.5ms 97.1MB 800ms 100ms pypy 3.8.13
python 3-m.py 656ms 4.0ms 16.3MB 1163ms 30ms pyston 3.8.12
python 3-m.py 932ms 8.3ms 15.3MB 1690ms 33ms cpython 3.10.4
java 3-m.java 1174ms 140ms 173.3MB 1777ms 53ms graal/jvm 17.0.3

mandelbrot

Input: 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java timeout 0.0ms 0.0MB 0ms 0ms graal/jvm 17.0.3
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 18.0.1
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 18.0.1
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 18.0.1
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 18.0.1

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 764ms 19ms 539.3MB 980ms 110ms openjdk 19
java 1.java 780ms 7.5ms 436.8MB 893ms 83ms openjdk 19
java 1.java 802ms 12ms 404.2MB 913ms 93ms openjdk 18.0.1
java 2.java 871ms 13ms 565.4MB 993ms 170ms openjdk 18.0.1
java 1.java 1085ms 6.8ms 319.6MB 880ms 80ms graal/jvm 17.0.3
java 2.java 1416ms 25ms 1046.7MB 1007ms 677ms openjdk/zgc 18.0.1
java 1.java 1467ms 5.1ms 1058.4MB 983ms 703ms openjdk/zgc 18.0.1

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 489ms 6.8ms 286.1MB 513ms 60ms openjdk 18.0.1
java 1.java 491ms 9.7ms 288.9MB 507ms 63ms openjdk 19
java 1.java 870ms 1.9ms 365.7MB 693ms 97ms graal/jvm 17.0.3
java 1.java 952ms 3.7ms 751.8MB 610ms 470ms openjdk/zgc 18.0.1
python 1.py 2718ms 66ms 293.9MB 2520ms 183ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 215ms 3.7ms 170.3MB 240ms 33ms openjdk 19
java 1.java 218ms 2.5ms 172.0MB 227ms 43ms openjdk 18.0.1
python 1.py 387ms 1.3ms 144.6MB 327ms 43ms pypy 3.8.13
java 1.java 422ms 10.0ms 352.5MB 247ms 223ms openjdk/zgc 18.0.1
java 1.java 585ms 6.4ms 245.8MB 370ms 73ms graal/jvm 17.0.3
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 551ms 5.5ms 40.5MB 567ms 13ms openjdk 18.0.1
java 1.java 554ms 3.0ms 39.8MB 567ms 10ms openjdk 19
java 1.java 602ms 0.9ms 40.9MB 573ms 53ms openjdk/zgc 18.0.1
java 1.java 856ms 5.8ms 83.0MB 570ms 23ms graal/jvm 17.0.3
java 2.java 1864ms 6.1ms 544.3MB 1893ms 117ms openjdk 19
java 2.java 1934ms 11ms 547.2MB 1927ms 157ms openjdk 18.0.1
python 2.py 2186ms 36ms 79.8MB 2157ms 13ms pypy 3.8.13
java 2.java 2548ms 12ms 1221.8MB 1943ms 790ms openjdk/zgc 18.0.1
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 2.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12
python 2.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 135ms 3.2ms 40.6MB 147ms 17ms openjdk 18.0.1
java 1.java 136ms 2.9ms 41.5MB 147ms 17ms openjdk 19
java 1.java 188ms 6.9ms 38.4MB 160ms 53ms openjdk/zgc 18.0.1
python 2.py 282ms 2.1ms 79.5MB 257ms 10ms pypy 3.8.13
java 2.java 410ms 4.1ms 337.4MB 470ms 83ms openjdk 19
java 2.java 418ms 12ms 322.7MB 483ms 73ms openjdk 18.0.1
java 1.java 452ms 2.8ms 88.4MB 170ms 23ms graal/jvm 17.0.3
python 1.py 590ms 2.3ms 79.7MB 563ms 10ms pypy 3.8.13
java 2.java 668ms 2.0ms 471.8MB 523ms 297ms openjdk/zgc 18.0.1
python 1.py 1463ms 3.4ms 8.6MB 1450ms 0ms pyston 3.8.12
python 2.py 2152ms 28ms 8.5MB 2140ms 0ms pyston 3.8.12
python 1.py 4709ms 32ms 7.3MB 4693ms 0ms cpython 3.10.4
python 2.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2.java 927ms 2.1ms 48.9MB 960ms 23ms openjdk 18.0.1
java 2.java 928ms 5.3ms 50.1MB 963ms 17ms openjdk 19
java 2.java 945ms 3.6ms 47.6MB 930ms 57ms openjdk/zgc 18.0.1
java 1.java 1022ms 23ms 106.6MB 980ms 80ms openjdk/zgc 18.0.1
java 1.java 1344ms 124ms 81.9MB 1363ms 27ms openjdk 19
java 1.java 1446ms 54ms 80.8MB 1473ms 17ms openjdk 18.0.1
java 1-m.java 1501ms 185ms 169.4MB 2260ms 57ms graal/jvm 17.0.3
java 2-m.java 1861ms 8.6ms 131.2MB 3433ms 53ms graal/jvm 17.0.3
python 1.py 4135ms 8.4ms 391.3MB 4000ms 113ms pypy 3.8.13
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 1.java 291ms 1.2ms 57.3MB 267ms 63ms openjdk/zgc 18.0.1
java 1.java 303ms 5.3ms 57.6MB 337ms 7ms openjdk 19
java 1.java 305ms 8.1ms 59.0MB 327ms 20ms openjdk 18.0.1
java 2.java 308ms 1.8ms 43.1MB 343ms 13ms openjdk 18.0.1
java 2.java 311ms 1.2ms 46.3MB 357ms 7ms openjdk 19
java 2.java 335ms 1.3ms 43.4MB 330ms 50ms openjdk/zgc 18.0.1
java 1.java 645ms 7.3ms 138.8MB 467ms 47ms graal/jvm 17.0.3
java 2.java 927ms 5.2ms 131.1MB 1097ms 43ms graal/jvm 17.0.3
python 1.py 1053ms 100ms 215.9MB 993ms 40ms pypy 3.8.13
python 1.py 2722ms 31ms 86.4MB 2687ms 17ms pyston 3.8.12
python 1.py 4283ms 21ms 85.9MB 4240ms 27ms cpython 3.10.4

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 2762ms 3.2ms 9.4MB 2727ms 17ms pyston 3.8.12
python 4.py 2782ms 2.3ms 8.5MB 2740ms 23ms cpython 3.10.4
python 4.py 2800ms 13ms 119.5MB 2757ms 27ms pypy 3.8.13
java 1.java timeout 0.0ms 0.0MB 0ms 0ms graal/jvm 17.0.3
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 18.0.1
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 1.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 18.0.1

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 655ms 0.7ms 9.1MB 643ms 0ms pyston 3.8.12
python 4.py 666ms 2.4ms 8.3MB 650ms 0ms cpython 3.10.4
python 4.py 694ms 12ms 84.5MB 663ms 13ms pypy 3.8.13
java 1.java 1363ms 13ms 396.9MB 1753ms 97ms graal/jvm 17.0.3
java 1.java 1532ms 15ms 240.8MB 2047ms 80ms openjdk 19
java 1.java 1539ms 11ms 250.8MB 1873ms 60ms openjdk 18.0.1
java 1.java 1946ms 0.8ms 933.1MB 1893ms 633ms openjdk/zgc 18.0.1

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 3343ms 4.3ms 264.1MB 3253ms 80ms pypy 3.8.13
java 3.java timeout 0.0ms 0.0MB 0ms 0ms graal/jvm 17.0.3
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 18.0.1
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 3.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 18.0.1
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 469ms 1.3ms 103.4MB 423ms 30ms pypy 3.8.13
python 1.py 745ms 2.2ms 30.4MB 707ms 17ms pyston 3.8.12
python 1.py 871ms 1.3ms 31.0MB 840ms 20ms cpython 3.10.4
java 3.java 1053ms 6.1ms 110.5MB 1383ms 37ms openjdk 18.0.1
java 3.java 1068ms 26ms 107.7MB 1407ms 37ms openjdk 19
java 3.java 1089ms 3.5ms 193.4MB 1453ms 70ms graal/jvm 17.0.3
java 3.java 1162ms 13ms 159.2MB 1340ms 123ms openjdk/zgc 18.0.1

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 4196ms 119ms 114.4MB 8067ms 43ms graal/jvm 17.0.3
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 18.0.1
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk 19
java 2.java timeout 0.0ms 0.0MB 0ms 0ms openjdk/zgc 18.0.1
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 1250ms 41ms 113.4MB 2290ms 43ms graal/jvm 17.0.3
java 2-m.java 1869ms 283ms 40.1MB 3540ms 17ms openjdk 19
java 2-m.java 2399ms 256ms 38.9MB 4587ms 13ms openjdk 18.0.1
java 2-m.java 2632ms 59ms 38.7MB 4990ms 53ms openjdk/zgc 18.0.1
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
java 2-m.java 550ms 46ms 39.9MB 977ms 10ms openjdk 19
java 2-m.java 719ms 15ms 40.3MB 1293ms 23ms openjdk 18.0.1
java 2.java 745ms 21ms 103.0MB 733ms 23ms graal/jvm 17.0.3
java 2-m.java 782ms 4.4ms 39.0MB 1343ms 57ms openjdk/zgc 18.0.1
python 8-m.py 3295ms 48ms 110.4MB 5600ms 377ms pypy 3.8.13
python 8.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 8.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1216ms 5.5ms 196.8MB 1140ms 60ms pypy 3.8.13
java 1-m.java 3243ms 64ms 199.4MB 6117ms 97ms loom 19
python 1.py timeout 0.0ms 0.0MB 0ms 0ms cpython 3.10.4
python 1.py timeout 0.0ms 0.0MB 0ms 0ms pyston 3.8.12

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 293ms 12ms 95.1MB 257ms 17ms pypy 3.8.13
java 1-m.java 731ms 33ms 110.8MB 1270ms 53ms loom 19
python 1.py 965ms 4.9ms 17.2MB 947ms 3ms pyston 3.8.12
python 1.py 1003ms 35ms 17.1MB 967ms 0ms cpython 3.10.4