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 59 122 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 3,609
C# 8.0.115 34 5,795 167x
Java javac 21.0.7 42 4,595 108x
Go go version go1.22.2 linux/amd64 39 15,639 396x
Pascal 3.2.2 58 32,878 557x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,279 77x

This is what it takes to calculate the 32nd Fibonacci number using different algorithms:

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.01 .0000000000046566 31729858 0 .0
cpp/loop 115 268435456 1.56 .0000000058114528 6104493317 22 3.8
cpp/matrixes 165 134217728 1.35 .0000000100582838 5272006311 39 3.9
go/fast n/a 134217728 1.57 .0000000116974115 6105539623 45 3.8
cpp/binpow-matrix 160 67108864 1.34 .0000000199675559 5248120401 78 3.9
haskell/iterate 906 4194304 1.40 .0000003337860107 5517835943 1315 3.9
haskell/zipwith 985 4194304 1.40 .0000003337860107 5462727383 1302 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 3985331195 1900 3.9
haskell/tail_recursion 781 2097152 1.04 .0000004959106445 4072867828 1942 3.9
cpp/interpreter 2946 65536 1.12 .0000170898437500 4379322395 66823 3.9
cpp/static_member_functions 69 256 1.50 .0058593750000000 5860034738 22890760 3.9
cpp/inlines 68 256 1.51 .0058984375000000 5883015134 22980527 3.9
cpp/recursion 68 256 1.51 .0058984375000000 5957822242 23272743 3.9
csharp/Functions n/a 256 2.27 .0088671875000000 8872341111 34657582 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8874671277 34666684 3.9
cpp/decorators 198 256 2.53 .0098828125000000 9853787612 38491357 3.9
go/recursion n/a 256 2.60 .0101562500000000 10100619722 39455545 3.9
java/Recursion n/a 256 2.73 .0106640625000000 10669707733 41678545 3.9
java/Functions n/a 256 2.74 .0107031250000000 10820339118 42266949 3.9
cpp/stack_objects 82 256 2.85 .0111328125000000 11128814132 43471930 3.9
cpp/classes 82 256 2.86 .0111718750000000 11151992106 43562469 3.9
pascal/recursion n/a 256 3.87 .0151171875000000 15099983442 58984310 3.9
haskell/recursion 786 256 3.91 .0152734375000000 15194078791 59351870 3.9
cpp/functions 86 256 6.16 .0240625000000000 24006039626 93773592 3.9
haskell/polymorphic_recursion 2092 256 6.92 .0270312500000000 26942654755 105244745 3.9
haskell/objects 968 256 8.05 .0314453125000000 31278224584 122180564 3.9
haskell/adt 916 256 17.64 .0689062500000000 68592704816 267940253 3.9
cpp/novirtual 211 256 88.51 .3457421875000000 344922840512 1347354845 3.9
cpp/functions_with_new 200 256 233.97 .9139453125000000 912094073153 3562867473 3.9
rust/structs 707 256 238.68 .9323437500000000 923923567415 3609076435 3.9
java/Records n/a 16 18.11 1.1318750000000000 70633426639 4414589164 3.9
java/Objects n/a 16 18.81 1.1756250000000000 73533604872 4595850304 3.9
cpp/lambdas 450 16 19.53 1.2206250000000000 76201042209 4762565138 3.9
csharp/Objects n/a 8 11.70 1.4625000000000000 46364383499 5795547937 4.0
csharp/Structs n/a 8 12.65 1.5812500000000000 49131950402 6141493800 3.9
cpp/objects 511 8 14.95 1.8687500000000000 58238525647 7279815705 3.9
go/structs n/a 4 15.96 3.9900000000000000 62557636238 15639409059 3.9
pascal/Objects n/a 2 16.83 8.4150000000000000 65757161860 32878580930 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-07 by @yegor256 at "Linux ip-172-31-17-207 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.