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,608
C# 8.0.116 34 5,743 165x
Java javac 21.0.7 41 4,588 110x
Go go version go1.22.2 linux/amd64 39 15,681 397x
Pascal 3.2.2 58 32,725 555x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,356 78x

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 31612988 0 .0
cpp/loop 115 268435456 1.56 .0000000058114528 6094087436 22 3.8
cpp/matrixes 165 134217728 1.35 .0000000100582838 5267241851 39 3.9
go/fast n/a 134217728 1.56 .0000000116229057 6102642226 45 3.9
cpp/binpow-matrix 160 67108864 1.34 .0000000199675559 5245286368 78 3.9
haskell/iterate 906 4194304 1.41 .0000003361701965 5549698308 1323 3.9
haskell/zipwith 985 4194304 1.41 .0000003361701965 5510038706 1313 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 3993646617 1904 3.9
haskell/tail_recursion 781 2097152 1.04 .0000004959106445 4079107222 1945 3.9
cpp/interpreter 2946 65536 1.12 .0000170898437500 4492661943 68552 4.0
cpp/inlines 68 256 1.51 .0058984375000000 5876258467 22954134 3.9
cpp/recursion 68 256 1.51 .0058984375000000 5875388464 22950736 3.9
cpp/static_member_functions 69 256 1.51 .0058984375000000 5861400506 22896095 3.9
csharp/Functions n/a 256 2.27 .0088671875000000 8872147724 34656827 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8871939802 34656014 3.9
cpp/decorators 198 256 2.53 .0098828125000000 10200407435 39845341 4.0
go/recursion n/a 256 2.59 .0101171875000000 10091126521 39418462 3.9
java/Functions n/a 256 2.74 .0107031250000000 10662230132 41649336 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10657668800 41631518 3.9
cpp/classes 82 256 2.86 .0111718750000000 11127033665 43464975 3.9
cpp/stack_objects 82 256 2.86 .0111718750000000 11124074838 43453417 3.9
pascal/recursion n/a 256 3.87 .0151171875000000 15093172373 58957704 3.9
haskell/recursion 786 256 3.90 .0152343750000000 15188501524 59330084 3.9
cpp/functions 86 256 6.16 .0240625000000000 23997795076 93741387 3.9
haskell/polymorphic_recursion 2092 256 6.90 .0269531250000000 27058637625 105697803 3.9
haskell/objects 968 256 8.05 .0314453125000000 31318489216 122337848 3.9
haskell/adt 916 256 17.73 .0692578125000000 69301731815 270709889 3.9
cpp/novirtual 211 256 88.93 .3473828125000000 344747834262 1346671227 3.9
cpp/functions_with_new 200 256 233.68 .9128125000000000 912579887788 3564765186 3.9
rust/structs 707 256 237.64 .9282812500000000 923790307702 3608555889 3.9
java/Records n/a 16 18.13 1.1331250000000000 70497016398 4406063524 3.9
java/Objects n/a 16 18.85 1.1781250000000000 73417903808 4588618988 3.9
cpp/lambdas 450 16 19.53 1.2206250000000000 76073458228 4754591139 3.9
csharp/Objects n/a 8 11.72 1.4650000000000000 45944958117 5743119764 3.9
csharp/Structs n/a 8 12.61 1.5762500000000000 49210901495 6151362686 3.9
cpp/objects 511 8 15.24 1.9050000000000000 58848881401 7356110175 3.9
go/structs n/a 4 15.91 3.9775000000000000 62725799567 15681449891 3.9
pascal/Objects n/a 2 16.72 8.3600000000000000 65451333149 32725666574 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.