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 58 122 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 3,585
C# 8.0.110 34 5,707 164x
Java javac 21.0.4 41 4,577 109x
Go go version go1.22.2 linux/amd64 39 15,913 403x
Pascal 3.2.2 58 32,705 554x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,538 80x

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 30335818 0 NaN
cpp/loop 115 268435456 1.59 .0000000059232115 6100569370 22 3.7
cpp/matrixes 165 134217728 1.35 .0000000100582838 5266875924 39 3.9
go/fast n/a 134217728 1.59 .0000000118464231 6198286134 46 3.9
cpp/binpow-matrix 160 67108864 1.34 .0000000199675559 5244734359 78 3.9
haskell/iterate 906 4194304 1.41 .0000003361701965 5517439943 1315 3.9
haskell/zipwith 985 4194304 1.41 .0000003361701965 5457610225 1301 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 3975489264 1895 3.9
haskell/tail_recursion 781 2097152 1.04 .0000004959106445 4047597490 1930 3.9
cpp/interpreter 2946 65536 1.15 .0000175476074218 4436594465 67697 3.9
cpp/recursion 68 256 1.50 .0058593750000000 5868031229 22921996 3.9
cpp/inlines 68 256 1.51 .0058984375000000 5864776227 22909282 3.9
cpp/static_member_functions 69 256 1.51 .0058984375000000 5883926378 22984087 3.9
csharp/Functions n/a 256 2.27 .0088671875000000 8867425823 34638382 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8871086775 34652682 3.9
cpp/decorators 198 256 2.56 .0100000000000000 10192635611 39814982 4.0
go/recursion n/a 256 2.60 .0101562500000000 10090303943 39415249 3.9
java/Functions n/a 256 2.74 .0107031250000000 10717333899 41864585 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10726668930 41901050 3.9
cpp/classes 82 256 2.86 .0111718750000000 11124311647 43454342 3.9
cpp/stack_objects 82 256 2.86 .0111718750000000 11124580695 43455393 3.9
pascal/recursion n/a 256 3.88 .0151562500000000 15092724060 58955953 3.9
haskell/recursion 786 256 3.89 .0151953125000000 15098710812 58979339 3.9
cpp/functions 86 256 6.16 .0240625000000000 23986261619 93696334 3.9
haskell/polymorphic_recursion 2092 256 6.80 .0265625000000000 27458302556 107258994 4.0
haskell/objects 968 256 8.06 .0314843750000000 31387897692 122608975 3.9
haskell/adt 916 256 17.54 .0685156250000000 68371719560 267077029 3.9
cpp/novirtual 211 256 89.90 .3511718750000000 351206553925 1371900601 3.9
cpp/functions_with_new 200 256 229.88 .8979687500000000 896939202109 3503668758 3.9
rust/structs 707 256 238.05 .9298828125000000 917987568288 3585888938 3.9
java/Records n/a 16 18.12 1.1325000000000000 70668034263 4416752141 3.9
java/Objects n/a 16 18.82 1.1762500000000000 73244770995 4577798187 3.9
cpp/lambdas 450 16 19.24 1.2025000000000000 75207602171 4700475135 3.9
csharp/Objects n/a 8 11.63 1.4537500000000000 45662110196 5707763774 3.9
csharp/Structs n/a 8 12.56 1.5700000000000000 48848669421 6106083677 3.9
cpp/objects 511 8 15.30 1.9125000000000000 60307873811 7538484226 3.9
go/structs n/a 4 16.22 4.0550000000000000 63655208689 15913802172 3.9
pascal/Objects n/a 2 16.73 8.3650000000000000 65410189478 32705094739 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 2024-10-16 by @yegor256 at "Linux ip-172-31-24-77 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.