Python VS C++ benchmarks

Current benchmark data was generated on Sat Jan 28 2023, 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
python 1.py 3016ms 52ms 271.6MB 2870ms 130ms pypy 3.9.16
python 1.py timeout 0.0ms 40.9MB 4977ms 7ms cpython 3.11.1
python 1.py timeout 0.0ms 40.2MB 4900ms 80ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 113ms 3.4ms 80.6MB 87ms 10ms pypy 3.9.16
python 1.py 613ms 1.2ms 12.0MB 583ms 10ms pyston 3.8.12
python 1.py 972ms 3.3ms 12.5MB 957ms 3ms cpython 3.11.1

coro-prime-sieve

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1646ms 35ms 193.2MB 1543ms 87ms pypy 3.9.16
python 1.py timeout 0.0ms 20.2MB 4973ms 7ms cpython 3.11.1
python 1.py timeout 0.0ms 17.2MB 4973ms 3ms pyston 3.8.12

Input: 1000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 320ms 4.8ms 92.8MB 280ms 20ms pypy 3.9.16
python 1.py 818ms 1.1ms 20.0MB 797ms 3ms cpython 3.11.1
python 1.py 943ms 6.4ms 16.7MB 923ms 3ms pyston 3.8.12

edigits

Input: 250001

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 711ms 11ms 81.6MB 680ms 13ms pypy 3.9.16
python 1.py 1658ms 0.8ms 10.1MB 1643ms 0ms cpython 3.11.1
python 1.py 2817ms 53ms 9.7MB 2807ms 0ms pyston 3.8.12

Input: 100000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 193ms 3.6ms 78.5MB 160ms 17ms pypy 3.9.16
python 1.py 301ms 0.7ms 9.4MB 290ms 0ms cpython 3.11.1
python 1.py 481ms 1.1ms 9.0MB 470ms 0ms pyston 3.8.12

fasta

Input: 2500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 3281ms 110ms 88.1MB 3240ms 23ms pypy 3.9.16
python 5-m.py 4072ms 15ms 13.5MB 5707ms 977ms cpython 3.11.1
python 1.py 4085ms 11ms 8.0MB 4063ms 7ms pyston 3.8.12
python 5-m.py 4087ms 56ms 12.5MB 6220ms 1000ms pyston 3.8.12
python 5-m.py 4461ms 125ms 82.8MB 5007ms 1030ms pypy 3.9.16
python 1.py timeout 0.0ms 8.5MB 4990ms 0ms cpython 3.11.1

Input: 250000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 430ms 8.6ms 7.9MB 413ms 0ms pyston 3.8.12
python 1.py 444ms 84ms 79.3MB 410ms 20ms pypy 3.9.16
python 5-m.py 468ms 23ms 12.7MB 667ms 150ms pyston 3.8.12
python 5-m.py 472ms 3.0ms 13.5MB 617ms 113ms cpython 3.11.1
python 1.py 603ms 4.7ms 8.6MB 590ms 0ms cpython 3.11.1
python 5-m.py 838ms 30ms 82.5MB 903ms 487ms pypy 3.9.16

helloworld

Input: QwQ

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 1.7ms 0.8ms 2.4MB 0ms 0ms g++ 12.2.0
cpp 1.cpp 2.1ms 0.6ms 1.4MB 0ms 0ms clang++ 14.0.0
python 1.py 13ms 0.4ms 7.3MB 10ms 0ms pyston 3.8.12
python 1.py 14ms 1.4ms 8.4MB 10ms 0ms cpython 3.11.1
python 1.py 38ms 3.1ms 51.6MB 14ms 10ms pypy 3.9.16

http-server

Input: 3000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1489ms 10ms 35.2MB 1097ms 800ms pyston 3.8.12
python 1.py 1783ms 2.7ms 30.0MB 1437ms 763ms cpython 3.11.1
python 1.py 4609ms 150ms 127.8MB 3567ms 920ms pypy 3.9.16

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 350ms 1.8ms 29.5MB 260ms 137ms pyston 3.8.12
python 1.py 365ms 1.5ms 24.8MB 303ms 113ms cpython 3.11.1
python 1.py 1188ms 74ms 104.0MB 950ms 210ms pypy 3.9.16

json-serde

Input: sample 5000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 254ms 1.2ms 41.5MB 230ms 10ms cpython 3.11.1
python 1.py 278ms 19ms 38.9MB 243ms 20ms pyston 3.8.12
python 1.py 411ms 17ms 104.6MB 367ms 27ms pypy 3.9.16

Input: canada 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 2342ms 8.5ms 223.0MB 2233ms 97ms cpython 3.11.1
python 1.py 2431ms 35ms 220.6MB 2267ms 150ms pyston 3.8.12
python 1.py 2537ms 19ms 245.2MB 2410ms 110ms pypy 3.9.16

knucleotide

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 3-m.py 4291ms 242ms 202.2MB 7437ms 357ms pypy 3.9.16
python 3.py timeout 0.0ms 35.0MB 87ms 17ms cpython 3.11.1
python 3.py timeout 0.0ms 34.3MB 73ms 17ms pyston 3.8.12

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 3-m.py 618ms 72ms 94.3MB 927ms 110ms pypy 3.9.16
python 3-m.py 737ms 14ms 17.6MB 1307ms 20ms pyston 3.8.12
python 3-m.py 843ms 37ms 16.9MB 1520ms 27ms cpython 3.11.1

lru

Input: 1000 1000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 2.py 212ms 19ms 77.3MB 177ms 13ms pypy 3.9.16
python 1.py 248ms 4.0ms 78.2MB 207ms 23ms pypy 3.9.16
python 1.py 976ms 2.0ms 9.0MB 960ms 0ms pyston 3.8.12
python 2.py 1156ms 1.7ms 8.7MB 1140ms 0ms pyston 3.8.12
python 1.py 1300ms 7.9ms 9.3MB 1287ms 0ms cpython 3.11.1
python 2.py 1494ms 5.2ms 9.1MB 1477ms 0ms cpython 3.11.1

Input: 1000 3000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 2.py 475ms 2.8ms 77.2MB 443ms 10ms pypy 3.9.16
python 1.py 512ms 11ms 78.8MB 480ms 17ms pypy 3.9.16
python 1.py 2900ms 12ms 9.0MB 2880ms 3ms pyston 3.8.12
python 2.py 3456ms 28ms 8.8MB 3440ms 0ms pyston 3.8.12
python 1.py 3892ms 45ms 9.5MB 3877ms 0ms cpython 3.11.1
python 2.py 4470ms 72ms 9.1MB 4453ms 0ms cpython 3.11.1

Input: 100 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 2.py 141ms 3.5ms 77.2MB 110ms 17ms pypy 3.9.16
python 1.py 171ms 15ms 78.2MB 140ms 13ms pypy 3.9.16
python 1.py 476ms 3.0ms 8.7MB 460ms 0ms pyston 3.8.12
python 2.py 539ms 3.6ms 8.2MB 523ms 0ms pyston 3.8.12
python 1.py 619ms 4.0ms 8.9MB 607ms 0ms cpython 3.11.1
python 2.py 745ms 5.0ms 8.4MB 733ms 0ms cpython 3.11.1

merkletrees

Input: 17

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 3586ms 375ms 292.5MB 3383ms 180ms pypy 3.9.16
python 1.py timeout 0.0ms 93.0MB 4947ms 33ms cpython 3.11.1
python 1.py timeout 0.0ms 130.3MB 4947ms 30ms pyston 3.8.12

Input: 15

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 543ms 129ms 138.5MB 483ms 47ms pypy 3.9.16
python 1.py timeout 0.0ms 37.3MB 4967ms 17ms cpython 3.11.1
python 1.py timeout 0.0ms 41.4MB 4963ms 13ms pyston 3.8.12

nbody

Input: 5000000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 225ms 0.5ms 1.3MB 213ms 0ms g++ 12.2.0
cpp 0-i.cpp 255ms 3.2ms 1.4MB 240ms 0ms clang++ 14.0.0
cpp 1.cpp 326ms 1.8ms 1.4MB 313ms 0ms clang++ 14.0.0
cpp 1.cpp 341ms 1.0ms 1.3MB 330ms 0ms g++ 12.2.0
python 2.py 2692ms 149ms 77.4MB 2660ms 13ms pypy 3.9.16
python 1.py 3533ms 41ms 76.5MB 3500ms 17ms pypy 3.9.16
python 1.py timeout 0.0ms 8.4MB 4983ms 0ms cpython 3.11.1
python 2.py timeout 0.0ms 8.6MB 4990ms 0ms cpython 3.11.1
python 1.py timeout 0.0ms 8.4MB 4977ms 3ms pyston 3.8.12
python 2.py timeout 0.0ms 8.0MB 4990ms 0ms pyston 3.8.12

Input: 500000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 0-i.cpp 25ms 0.0ms 1.3MB 17ms 0ms g++ 12.2.0
cpp 0-i.cpp 29ms 2.1ms 1.4MB 20ms 0ms clang++ 14.0.0
cpp 1.cpp 36ms 0.8ms 1.4MB 27ms 0ms clang++ 14.0.0
cpp 1.cpp 36ms 0.4ms 1.4MB 30ms 0ms g++ 12.2.0
python 2.py 305ms 26ms 77.0MB 277ms 10ms pypy 3.9.16
python 1.py 400ms 3.4ms 76.4MB 373ms 10ms pypy 3.9.16
python 1.py 1193ms 1.0ms 8.3MB 1180ms 0ms pyston 3.8.12
python 2.py 1636ms 28ms 7.9MB 1623ms 0ms pyston 3.8.12
python 2.py 3404ms 24ms 8.6MB 3393ms 0ms cpython 3.11.1
python 1.py 3437ms 149ms 8.4MB 3423ms 0ms cpython 3.11.1

nsieve

Input: 12

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 644ms 12ms 7.8MB 633ms 0ms g++ 12.2.0
cpp 1.cpp 711ms 5.6ms 7.7MB 697ms 0ms clang++ 14.0.0
python 1.py 4480ms 211ms 389.1MB 4330ms 133ms pypy 3.9.16
python 1.py timeout 0.0ms 321.1MB 4937ms 50ms cpython 3.11.1
python 2.py timeout 0.0ms 633.6MB 4690ms 293ms cpython 3.11.1
python 2.py timeout 0.0ms 1013.7MB 4620ms 360ms pypy 3.9.16
python 1.py timeout 0.0ms 320.5MB 4897ms 87ms pyston 3.8.12
python 2.py timeout 0.0ms 633.2MB 4577ms 403ms pyston 3.8.12

Input: 10

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 1.cpp 154ms 2.5ms 4.0MB 143ms 0ms g++ 12.2.0
cpp 1.cpp 169ms 0.6ms 4.0MB 160ms 0ms clang++ 14.0.0
python 1.py 1085ms 58ms 213.2MB 1033ms 37ms pypy 3.9.16
python 2.py 1345ms 7.3ms 164.4MB 1253ms 70ms pyston 3.8.12
python 2.py 1668ms 7.8ms 164.8MB 1593ms 60ms cpython 3.11.1
python 1.py 1746ms 35ms 86.1MB 1713ms 20ms pyston 3.8.12
python 2.py 1769ms 128ms 266.8MB 1623ms 123ms pypy 3.9.16
python 1.py 2971ms 17ms 86.7MB 2933ms 20ms cpython 3.11.1

pidigits

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 2780ms 3.4ms 9.1MB 2750ms 10ms pyston 3.8.12
python 4.py 2785ms 5.2ms 9.4MB 2753ms 20ms cpython 3.11.1
python 4.py 3067ms 120ms 117.1MB 3013ms 37ms pypy 3.9.16

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 4.py 658ms 0.4ms 8.8MB 643ms 0ms pyston 3.8.12
python 4.py 660ms 1.0ms 9.1MB 650ms 0ms cpython 3.11.1
python 4.py 776ms 32ms 81.6MB 747ms 13ms pypy 3.9.16

regex-redux

Input: 2500000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 3568ms 25ms 262.2MB 3440ms 110ms pypy 3.9.16
python 1.py timeout 0.0ms 108.4MB 4953ms 27ms cpython 3.11.1
python 1.py timeout 0.0ms 106.9MB 4930ms 50ms pyston 3.8.12

Input: 250000_in

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 501ms 2.5ms 100.6MB 457ms 27ms pypy 3.9.16
python 1.py 706ms 1.3ms 30.5MB 670ms 20ms pyston 3.8.12
python 1.py 828ms 1.2ms 31.9MB 793ms 17ms cpython 3.11.1

secp256k1

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 4446ms 11ms 8.6MB 4430ms 0ms pyston 3.8.12
python 1.py 4616ms 3.9ms 8.4MB 4600ms 0ms cpython 3.11.1
python 1.py timeout 0.0ms 84.1MB 4963ms 13ms pypy 3.9.16

Input: 500

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
python 1.py 1129ms 7.4ms 8.5MB 1113ms 0ms pyston 3.8.12
python 1.py 1163ms 3.5ms 8.4MB 1150ms 0ms cpython 3.11.1
python 1.py 1508ms 32ms 81.8MB 1473ms 17ms pypy 3.9.16

spectral-norm

Input: 8000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 1059ms 3.0ms 3.3MB 2077ms 0ms clang++ 14.0.0
cpp 7-m.cpp 1061ms 5.4ms 1.3MB 2080ms 0ms g++ 12.2.0
cpp 8-m.cpp 1065ms 0.4ms 1.4MB 2080ms 0ms g++ 12.2.0
cpp 8-m.cpp 1069ms 14ms 3.5MB 2080ms 0ms clang++ 14.0.0
cpp 6-im.cpp 2223ms 8.8ms 3.3MB 4353ms 3ms clang++ 14.0.0
cpp 6-im.cpp 2238ms 14ms 1.3MB 4390ms 0ms g++ 12.2.0
python 8.py timeout 0.0ms 16.5MB 57ms 7ms cpython 3.11.1
python 8.py timeout 0.0ms 105.2MB 717ms 120ms pypy 3.9.16
python 8.py timeout 0.0ms 17.7MB 57ms 23ms pyston 3.8.12

Input: 4000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 273ms 0.1ms 3.4MB 520ms 0ms clang++ 14.0.0
cpp 8-m.cpp 274ms 0.9ms 1.4MB 520ms 0ms g++ 12.2.0
cpp 7-m.cpp 275ms 2.4ms 1.3MB 520ms 0ms g++ 12.2.0
cpp 8-m.cpp 276ms 3.9ms 3.3MB 517ms 0ms clang++ 14.0.0
cpp 6-im.cpp 562ms 1.6ms 3.5MB 1087ms 0ms clang++ 14.0.0
cpp 6-im.cpp 566ms 3.0ms 1.4MB 1097ms 0ms g++ 12.2.0
python 8.py timeout 0.0ms 18.2MB 113ms 10ms cpython 3.11.1
python 8.py timeout 0.0ms 107.0MB 1267ms 210ms pypy 3.9.16
python 8.py timeout 0.0ms 17.2MB 160ms 20ms pyston 3.8.12

Input: 2000

lang code time stddev peak-mem mem time(user) time(sys) compiler compiler/runtime
cpp 7-m.cpp 75ms 0.9ms 1.3MB 130ms 0ms g++ 12.2.0
cpp 7-m.cpp 76ms 2.0ms 3.3MB 130ms 0ms clang++ 14.0.0
cpp 8-m.cpp 76ms 1.2ms 3.3MB 127ms 0ms clang++ 14.0.0
cpp 8-m.cpp 78ms 4.9ms 1.3MB 130ms 0ms g++ 12.2.0
cpp 6-im.cpp 149ms 0.8ms 3.3MB 270ms 0ms clang++ 14.0.0
cpp 6-im.cpp 151ms 1.5ms 1.3MB 277ms 0ms g++ 12.2.0
python 8-m.py 3558ms 133ms 107.0MB 6063ms 373ms pypy 3.9.16
python 8.py timeout 0.0ms 15.9MB 243ms 30ms cpython 3.11.1
python 8.py timeout 0.0ms 17.1MB 357ms 73ms pyston 3.8.12