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 1x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 0
C# 8.0.125 0 0 70x
Java javac 21.0.10 0 0 31x
Go go version go1.22.2 linux/amd64 0 0 205x
Pascal 3.2.2 0 0 479x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 0 81x

This is what it takes to calculate the 7th Fibonacci number using different algorithms:

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.00 0 1459074 0 NaN
cpp/loop 115 536870912 1.68 .0000000031292438 6458050264 12 3.8
go/fast n/a 268435456 1.59 .0000000059232115 6171772925 22 3.7
cpp/matrixes 165 268435456 1.66 .0000000061839818 6462732723 24 3.9
cpp/binpow-matrix 160 134217728 1.55 .0000000115483999 6064538595 45 3.9
cpp/static_member_functions 69 33554432 1.07 .0000000318884849 4166526158 124 3.9
cpp/inlines 68 33554432 1.10 .0000000327825546 4272365207 127 3.9
cpp/recursion 68 33554432 1.10 .0000000327825546 4272842051 127 3.9
csharp/Recursion n/a 33554432 1.72 .0000000512599945 6770160229 201 3.9
csharp/Functions n/a 33554432 1.74 .0000000518560409 6817638258 203 3.9
go/recursion n/a 33554432 1.98 .0000000590085983 7693475316 229 3.9
java/Functions n/a 16777216 1.03 .0000000613927841 4005898269 238 3.9
java/Recursion n/a 16777216 1.03 .0000000613927841 4009506469 238 3.9
cpp/classes 82 16777216 1.07 .0000000637769699 4170938450 248 3.9
cpp/stack_objects 82 16777216 1.07 .0000000637769699 4169825497 248 3.9
pascal/recursion n/a 16777216 1.45 .0000000864267349 5661763377 337 3.9
cpp/functions 86 8388608 1.18 .0000001406669616 4594610488 547 3.9
cpp/decorators 198 8388608 1.80 .0000002145767211 7175781794 855 4.0
haskell/zipwith 985 4194304 1.25 .0000002980232238 4911421682 1170 3.9
haskell/iterate 906 4194304 1.26 .0000003004074096 4923769269 1173 3.9
haskell/tail_recursion 781 4194304 1.41 .0000003361701965 5505592913 1312 3.9
haskell/object_dynamic 1113 4194304 1.43 .0000003409385681 5625773952 1341 3.9
haskell/recursion 786 4194304 1.61 .0000003838539123 6266924254 1494 3.9
haskell/polymorphic_recursion 2092 4194304 1.95 .0000004649162292 7606554906 1813 3.9
haskell/objects 968 4194304 2.13 .0000005078315734 8301790315 1979 3.9
haskell/adt 916 2097152 1.09 .0000005197525024 4276284782 2039 3.9
rust/structs 707 2097152 1.43 .0000006818771362 5515289837 2629 3.9
java/Objects n/a 524288 1.02 .0000019454956054 3942578723 7519 3.9
java/Records n/a 524288 1.02 .0000019454956054 3967885849 7568 3.9
cpp/novirtual 211 524288 1.04 .0000019836425781 4052555696 7729 3.9
csharp/Structs n/a 524288 1.82 .0000034713745117 7131310133 13601 3.9
csharp/Objects n/a 524288 1.91 .0000036430358886 7474027908 14255 3.9
cpp/interpreter 2946 262144 1.28 .0000048828125000 4995202525 19055 3.9
cpp/functions_with_new 200 262144 1.40 .0000053405761718 5485323375 20924 3.9
cpp/lambdas 450 262144 1.96 .0000074768066406 7681669790 29303 3.9
cpp/objects 511 131072 1.49 .0000113677978515 5809019107 44319 3.9
go/structs n/a 131072 1.55 .0000118255615234 6182394979 47167 4.0
pascal/Objects n/a 32768 1.36 .0000415039062500 5290744063 161460 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.