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.125 0 1 94x
Java javac 21.0.10 0 0 51x
Go go version go1.22.2 linux/amd64 0 4 265x
Pascal 3.2.2 0 13 493x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 3 81x

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 1455918 0 NaN
cpp/loop 115 268435456 1.10 .0000000040978193 4308066790 16 3.9
go/fast n/a 268435456 1.96 .0000000073015689 7628688040 28 3.8
cpp/matrixes 165 134217728 1.17 .0000000087171792 4574289796 34 3.9
cpp/binpow-matrix 160 67108864 1.17 .0000000174343585 4575387058 68 3.9
haskell/zipwith 985 4194304 1.30 .0000003099441528 5123294404 1221 3.9
haskell/iterate 906 4194304 1.32 .0000003147125244 5109347271 1218 3.9
haskell/object_dynamic 1113 4194304 1.74 .0000004148483276 6817507180 1625 3.9
haskell/tail_recursion 781 4194304 1.76 .0000004196166992 6854913111 1634 3.9
cpp/static_member_functions 69 524288 1.37 .0000026130676269 5346668972 10197 3.9
cpp/inlines 68 524288 1.38 .0000026321411132 5399716928 10299 3.9
cpp/recursion 68 524288 1.38 .0000026321411132 5403098631 10305 3.9
csharp/Functions n/a 262144 1.05 .0000040054321289 4141727853 15799 3.9
csharp/Recursion n/a 262144 1.05 .0000040054321289 4137683262 15784 3.9
go/recursion n/a 262144 1.20 .0000045776367187 4682339523 17861 3.9
java/Functions n/a 262144 1.27 .0000048446655273 4947156366 18871 3.9
java/Recursion n/a 262144 1.27 .0000048446655273 4945414747 18865 3.9
cpp/decorators 198 262144 1.29 .0000049209594726 4977526395 18987 3.9
cpp/classes 82 262144 1.32 .0000050354003906 5159069723 19680 3.9
cpp/stack_objects 82 262144 1.32 .0000050354003906 5160053285 19684 3.9
pascal/recursion n/a 262144 1.79 .0000068283081054 6992679288 26674 3.9
haskell/recursion 786 262144 1.87 .0000071334838867 7274984420 27751 3.9
cpp/interpreter 2946 131072 1.30 .0000099182128906 4864549137 37113 3.7
cpp/functions 86 131072 1.43 .0000109100341796 5566989426 42472 3.9
haskell/polymorphic_recursion 2092 131072 1.70 .0000129699707031 6533136941 49843 3.8
haskell/objects 968 131072 1.94 .0000148010253906 7594875667 57944 3.9
haskell/adt 916 65536 1.31 .0000199890136718 4852303404 74040 3.7
rust/structs 707 8192 1.16 .0001416015625000 4548747792 555267 3.9
cpp/novirtual 211 8192 1.32 .0001611328125000 5134238070 626738 3.9
java/Records n/a 4096 1.00 .0002441406250000 3835746235 936461 3.8
java/Objects n/a 4096 1.02 .0002490234375000 3964117085 967802 3.9
csharp/Objects n/a 4096 1.54 .0003759765625000 6093471931 1487664 4.0
csharp/Structs n/a 4096 1.61 .0003930664062500 6305795936 1539500 3.9
cpp/functions_with_new 200 4096 1.74 .0004248046875000 7186922638 1754619 4.1
cpp/lambdas 450 2048 1.19 .0005810546875000 4761203859 2324806 4.0
cpp/objects 511 2048 1.83 .0008935546875000 7123587132 3478314 3.9
go/structs n/a 1024 1.22 .0011914062500000 4854772921 4740989 4.0
pascal/Objects n/a 512 1.72 .0033593750000000 6744371897 13172601 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 2026-03-31 by @yegor256 at "Linux ip-172-31-16-55 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.