This is how much functions are faster than objects:

TPC
Language Compiler w/functions w/objects Ratio
Haskell The Glorious Glasgow Haskell Compilation System, version 9.4.7 0 0 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 0
C# 8.0.116 0 1 93x
Java javac 21.0.7 0 0 51x
Go go version go1.22.2 linux/amd64 0 4 269x
Pascal 3.2.2 0 13 493x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 3 79x

This is what it takes to calculate the 16th Fibonacci number using different algorithms:

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.00 0 1719009 0 NaN
cpp/loop 115 268435456 1.10 .0000000040978193 4304528917 16 3.9
go/fast n/a 268435456 1.97 .0000000073388218 7616452426 28 3.8
cpp/matrixes 165 134217728 1.17 .0000000087171792 4570447146 34 3.9
cpp/binpow-matrix 160 67108864 1.17 .0000000174343585 4572826951 68 3.9
haskell/zipwith 985 4194304 1.30 .0000003099441528 5119184820 1220 3.9
haskell/iterate 906 4194304 1.32 .0000003147125244 5141735978 1225 3.9
haskell/object_dynamic 1113 4194304 1.72 .0000004100799560 6806618995 1622 4.0
haskell/tail_recursion 781 4194304 1.77 .0000004220008850 6880729580 1640 3.9
cpp/inlines 68 524288 1.38 .0000026321411132 5397123812 10294 3.9
cpp/recursion 68 524288 1.38 .0000026321411132 5397339157 10294 3.9
cpp/static_member_functions 69 524288 1.38 .0000026321411132 5346332782 10197 3.9
csharp/Functions n/a 262144 1.05 .0000040054321289 4136947246 15781 3.9
csharp/Recursion n/a 262144 1.05 .0000040054321289 4133907587 15769 3.9
go/recursion n/a 262144 1.20 .0000045776367187 4676521250 17839 3.9
java/Functions n/a 262144 1.27 .0000048446655273 4944193353 18860 3.9
java/Recursion n/a 262144 1.27 .0000048446655273 4943959644 18859 3.9
cpp/decorators 198 262144 1.28 .0000048828125000 5183282173 19772 4.0
cpp/classes 82 262144 1.32 .0000050354003906 5157400272 19673 3.9
cpp/stack_objects 82 262144 1.32 .0000050354003906 5158040555 19676 3.9
pascal/recursion n/a 262144 1.79 .0000068283081054 6983944273 26641 3.9
haskell/recursion 786 262144 1.88 .0000071716308593 7262984517 27706 3.9
cpp/interpreter 2946 131072 1.21 .0000092315673828 4874305404 37187 4.0
cpp/functions 86 131072 1.43 .0000109100341796 5562503790 42438 3.9
haskell/polymorphic_recursion 2092 131072 1.68 .0000128173828125 6562549418 50068 3.9
haskell/objects 968 131072 1.95 .0000148773193359 7513603092 57324 3.9
haskell/adt 916 65536 1.30 .0000198364257812 4838634654 73831 3.7
rust/structs 707 8192 1.15 .0001403808593750 4500637435 549394 3.9
cpp/novirtual 211 8192 1.31 .0001599121093750 4998465161 610164 3.8
java/Records n/a 4096 1.01 .0002465820312500 3911031387 954841 3.9
java/Objects n/a 4096 1.02 .0002490234375000 3974089749 970236 3.9
csharp/Objects n/a 4096 1.55 .0003784179687500 6068882355 1481660 3.9
csharp/Structs n/a 4096 1.61 .0003930664062500 6308476905 1540155 3.9
cpp/functions_with_new 200 4096 1.69 .0004125976562500 6718420624 1640239 4.0
cpp/lambdas 450 2048 1.13 .0005517578125000 4412276624 2154431 3.9
cpp/objects 511 2048 1.73 .0008447265625000 6914323281 3376134 4.0
go/structs n/a 1024 1.23 .0012011718750000 4914366285 4799185 4.0
pascal/Objects n/a 512 1.71 .0033398437500000 6726660578 13138008 3.9

Program: File name as it's seen in the source code repository. ASM: Total number of Assembly instructions seen in the compiled .asm file; not every compiler provides this information though. Cycles: How many times the Fibonacci number has been calculated. Time: How many seconds it took to execute all calculations. SPC: How many seconds per each calculation. Ticks: How many total CPU ticks it took to execute all calculations, according to perf. TPC: How many ticks per a single calculation. GHz: TPC divided by SPC and divided by one billion; this is approximately how fast is the CPU; this metric for all programs is expected to have almost the same values, otherwise something is wrong with the method.

Maximum optimization is enabled in all compilers.

If you want to add another program to the list, just submit a pull request to yegor256/fibonacci.

Here is index.xml with the data. This is TeX summary.tex.

Built on 2025-05-19 by @yegor256 at "Linux ip-172-31-20-147 6.8.0-1016-aws #17-Ubuntu SMP Mon Sep 2 13:48:07 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux" machine.