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.122 34 5,706 164x
Java javac 21.0.9 41 4,594 110x
Go go version go1.22.2 linux/amd64 39 15,813 400x
Pascal 3.2.2 59 32,887 557x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,291 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.00 0 31664644 0 NaN
cpp/loop 115 268435456 1.56 .0000000058114528 6095840841 22 3.8
cpp/matrixes 165 134217728 1.35 .0000000100582838 5267466797 39 3.9
go/fast n/a 134217728 1.57 .0000000116974115 6095787568 45 3.8
cpp/binpow-matrix 160 67108864 1.35 .0000000201165676 5250808858 78 3.9
haskell/iterate 906 4194304 1.40 .0000003337860107 5567472378 1327 4.0
haskell/zipwith 985 4194304 1.41 .0000003361701965 5500949666 1311 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 4019201783 1916 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4090162590 1950 3.9
cpp/interpreter 2946 65536 1.12 .0000170898437500 4385964594 66924 3.9
cpp/static_member_functions 69 256 1.50 .0058593750000000 5846872529 22839345 3.9
cpp/inlines 68 256 1.51 .0058984375000000 5881092877 22973019 3.9
cpp/recursion 68 256 1.51 .0058984375000000 5878212833 22961768 3.9
csharp/Functions n/a 256 2.27 .0088671875000000 8877753067 34678722 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8877681153 34678442 3.9
go/recursion n/a 256 2.60 .0101562500000000 10101046892 39457214 3.9
java/Functions n/a 256 2.73 .0106640625000000 10665262928 41661183 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10663439169 41654059 3.9
cpp/classes 82 256 2.86 .0111718750000000 11135036695 43496237 3.9
cpp/stack_objects 82 256 2.86 .0111718750000000 11137352004 43505281 3.9
cpp/decorators 198 256 2.93 .0114453125000000 9853574154 38490524 3.4
pascal/recursion n/a 256 3.87 .0151171875000000 15105506970 59005886 3.9
haskell/recursion 786 256 3.90 .0152343750000000 15204701837 59393366 3.9
cpp/functions 86 256 6.16 .0240625000000000 24023000644 93839846 3.9
haskell/polymorphic_recursion 2092 256 6.98 .0272656250000000 26796175849 104672561 3.8
haskell/objects 968 256 8.06 .0314843750000000 31333674305 122397165 3.9
haskell/adt 916 256 17.83 .0696484375000000 68826236987 268852488 3.9
cpp/novirtual 211 256 88.47 .3455859375000000 345067407960 1347919562 3.9
cpp/functions_with_new 200 256 234.27 .9151171875000000 914800134290 3573438024 3.9
rust/structs 707 256 236.99 .9257421875000000 924099552218 3609763875 3.9
java/Records n/a 16 18.10 1.1312500000000000 70545377263 4409086078 3.9
java/Objects n/a 16 18.84 1.1775000000000000 73515182892 4594698930 3.9
cpp/lambdas 450 16 19.52 1.2200000000000000 76253845289 4765865330 3.9
csharp/Objects n/a 8 11.70 1.4625000000000000 45653351418 5706668927 3.9
csharp/Structs n/a 8 12.72 1.5900000000000000 50106760348 6263345043 3.9
cpp/objects 511 8 15.06 1.8825000000000000 58328553420 7291069177 3.9
go/structs n/a 4 16.11 4.0275000000000000 63252033322 15813008330 3.9
pascal/Objects n/a 2 16.79 8.3950000000000000 65775022999 32887511499 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-01-01 by @yegor256 at "Linux ip-172-31-22-94 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.