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

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 1519858 0 NaN
cpp/loop 115 536870912 1.66 .0000000030919909 6454793040 12 3.9
go/fast n/a 268435456 1.59 .0000000059232115 6194694012 23 3.9
cpp/matrixes 165 268435456 1.66 .0000000061839818 6455899883 24 3.9
cpp/binpow-matrix 160 134217728 1.56 .0000000116229057 6057584312 45 3.9
cpp/static_member_functions 69 33554432 1.07 .0000000318884849 4172019221 124 3.9
cpp/inlines 68 33554432 1.10 .0000000327825546 4270204672 127 3.9
cpp/recursion 68 33554432 1.10 .0000000327825546 4270449672 127 3.9
csharp/Recursion n/a 33554432 1.72 .0000000512599945 6754185287 201 3.9
csharp/Functions n/a 33554432 1.73 .0000000515580177 6817156490 203 3.9
go/recursion n/a 33554432 1.97 .0000000587105751 7686649966 229 3.9
java/Functions n/a 16777216 1.03 .0000000613927841 4005676370 238 3.9
java/Recursion n/a 16777216 1.03 .0000000613927841 4005287248 238 3.9
cpp/classes 82 16777216 1.07 .0000000637769699 4170489296 248 3.9
cpp/stack_objects 82 16777216 1.07 .0000000637769699 4169116207 248 3.9
pascal/recursion n/a 16777216 1.45 .0000000864267349 5655825242 337 3.9
cpp/functions 86 8388608 1.18 .0000001406669616 4589820486 547 3.9
cpp/decorators 198 8388608 1.70 .0000002026557922 6618488739 788 3.9
haskell/iterate 906 4194304 1.26 .0000003004074096 4894585544 1166 3.9
haskell/zipwith 985 4194304 1.26 .0000003004074096 4883590315 1164 3.9
haskell/tail_recursion 781 4194304 1.40 .0000003337860107 5497546592 1310 3.9
haskell/object_dynamic 1113 4194304 1.43 .0000003409385681 5622947535 1340 3.9
haskell/recursion 786 4194304 1.60 .0000003814697265 6284680875 1498 3.9
haskell/polymorphic_recursion 2092 4194304 1.94 .0000004625320434 7567484325 1804 3.9
haskell/objects 968 4194304 2.08 .0000004959106445 8120819210 1936 3.9
haskell/adt 916 2097152 1.11 .0000005292892456 4293885423 2047 3.9
rust/structs 707 2097152 1.48 .0000007057189941 5512683588 2628 3.7
java/Objects n/a 524288 1.00 .0000019073486328 3927163734 7490 3.9
java/Records n/a 524288 1.02 .0000019454956054 3954527265 7542 3.9
cpp/novirtual 211 524288 1.03 .0000019645690917 3965902255 7564 3.9
csharp/Structs n/a 524288 1.88 .0000035858154296 7159271537 13655 3.8
csharp/Objects n/a 524288 1.92 .0000036621093750 7552581249 14405 3.9
cpp/interpreter 2946 262144 1.24 .0000047302246093 4808518010 18343 3.9
cpp/functions_with_new 200 262144 1.38 .0000052642822265 5406388868 20623 3.9
cpp/lambdas 450 262144 1.87 .0000071334838867 7271967299 27740 3.9
cpp/objects 511 131072 1.42 .0000108337402343 5682805949 43356 4.0
go/structs n/a 131072 1.56 .0000119018554687 6304560442 48099 4.0
pascal/Objects n/a 32768 1.35 .0000411987304687 5289017968 161408 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.