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.115 0 0 70x
Java javac 21.0.7 0 0 31x
Go go version go1.22.2 linux/amd64 0 0 201x
Pascal 3.2.2 0 0 484x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 0 77x

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 1493709 0 NaN
cpp/loop 115 536870912 1.65 .0000000030733644 6459637623 12 3.9
go/fast n/a 268435456 1.59 .0000000059232115 6196174461 23 3.9
cpp/matrixes 165 268435456 1.66 .0000000061839818 6461311357 24 3.9
cpp/binpow-matrix 160 134217728 1.55 .0000000115483999 6060134945 45 3.9
cpp/static_member_functions 69 33554432 1.07 .0000000318884849 4154290598 123 3.9
cpp/inlines 68 33554432 1.10 .0000000327825546 4272470633 127 3.9
cpp/recursion 68 33554432 1.10 .0000000327825546 4273246792 127 3.9
csharp/Recursion n/a 33554432 1.73 .0000000515580177 6736080691 200 3.9
csharp/Functions n/a 33554432 1.74 .0000000518560409 6796928502 202 3.9
go/recursion n/a 33554432 1.98 .0000000590085983 7696285670 229 3.9
java/Functions n/a 16777216 1.03 .0000000613927841 4006105998 238 3.9
java/Recursion n/a 16777216 1.03 .0000000613927841 4008636697 238 3.9
cpp/classes 82 16777216 1.07 .0000000637769699 4170479233 248 3.9
cpp/stack_objects 82 16777216 1.07 .0000000637769699 4171470462 248 3.9
pascal/recursion n/a 16777216 1.45 .0000000864267349 5655092212 337 3.9
cpp/functions 86 8388608 1.18 .0000001406669616 4590182389 547 3.9
cpp/decorators 198 8388608 1.55 .0000001847743988 6715680830 800 4.3
haskell/zipwith 985 4194304 1.25 .0000002980232238 4904006688 1169 3.9
haskell/iterate 906 4194304 1.26 .0000003004074096 4952740262 1180 3.9
haskell/tail_recursion 781 4194304 1.39 .0000003314018249 5491671243 1309 3.9
haskell/object_dynamic 1113 4194304 1.45 .0000003457069396 5640379425 1344 3.9
haskell/recursion 786 4194304 1.62 .0000003862380981 6243280128 1488 3.9
haskell/polymorphic_recursion 2092 4194304 1.97 .0000004696846008 7628835479 1818 3.9
haskell/objects 968 2097152 1.02 .0000004863739013 3954055980 1885 3.9
haskell/adt 916 2097152 1.11 .0000005292892456 4274184017 2038 3.9
rust/structs 707 2097152 1.41 .0000006723403930 5612351681 2676 4.0
cpp/novirtual 211 524288 1.01 .0000019264221191 3963569779 7559 3.9
java/Objects n/a 524288 1.01 .0000019264221191 3948071904 7530 3.9
java/Records n/a 524288 1.02 .0000019454956054 3935861391 7507 3.9
csharp/Structs n/a 524288 1.83 .0000034904479980 7171492069 13678 3.9
csharp/Objects n/a 524288 1.91 .0000036430358886 7509704030 14323 3.9
cpp/interpreter 2946 262144 1.24 .0000047302246093 4817300591 18376 3.9
cpp/functions_with_new 200 262144 1.38 .0000052642822265 5382351187 20532 3.9
cpp/lambdas 450 262144 1.86 .0000070953369140 7277122550 27760 3.9
cpp/objects 511 131072 1.44 .0000109863281250 5550785514 42349 3.9
go/structs n/a 131072 1.56 .0000119018554687 6050120050 46158 3.9
pascal/Objects n/a 32768 1.37 .0000418090820312 5349151088 163243 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.