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.122 0 0 70x
Java javac 21.0.9 0 0 31x
Go go version go1.22.2 linux/amd64 0 0 208x
Pascal 3.2.2 0 0 485x
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 1400020 0 NaN
cpp/loop 115 536870912 1.66 .0000000030919909 6460910135 12 3.9
go/fast n/a 268435456 1.60 .0000000059604644 6187617029 23 3.9
cpp/matrixes 165 268435456 1.66 .0000000061839818 6459657887 24 3.9
cpp/binpow-matrix 160 134217728 1.56 .0000000116229057 6063244485 45 3.9
cpp/static_member_functions 69 33554432 1.07 .0000000318884849 4166128310 124 3.9
cpp/recursion 68 33554432 1.09 .0000000324845314 4274552227 127 3.9
cpp/inlines 68 33554432 1.10 .0000000327825546 4274078443 127 3.9
csharp/Recursion n/a 33554432 1.72 .0000000512599945 6759811324 201 3.9
csharp/Functions n/a 33554432 1.73 .0000000515580177 6806112986 202 3.9
go/recursion n/a 33554432 1.98 .0000000590085983 7696327263 229 3.9
java/Functions n/a 16777216 1.03 .0000000613927841 4008275661 238 3.9
java/Recursion n/a 16777216 1.03 .0000000613927841 4008581908 238 3.9
cpp/classes 82 16777216 1.07 .0000000637769699 4175383269 248 3.9
cpp/stack_objects 82 16777216 1.07 .0000000637769699 4175101516 248 3.9
pascal/recursion n/a 16777216 1.45 .0000000864267349 5662902832 337 3.9
cpp/functions 86 8388608 1.18 .0000001406669616 4592306875 547 3.9
cpp/decorators 198 8388608 1.71 .0000002038478851 6627242262 790 3.9
haskell/iterate 906 4194304 1.26 .0000003004074096 4953019277 1180 3.9
haskell/zipwith 985 4194304 1.26 .0000003004074096 4885924771 1164 3.9
haskell/tail_recursion 781 4194304 1.41 .0000003361701965 5480279898 1306 3.9
haskell/object_dynamic 1113 4194304 1.43 .0000003409385681 5604800883 1336 3.9
haskell/recursion 786 4194304 1.61 .0000003838539123 6231493017 1485 3.9
haskell/polymorphic_recursion 2092 4194304 1.96 .0000004673004150 7612985032 1815 3.9
haskell/objects 968 4194304 2.08 .0000004959106445 8146261353 1942 3.9
haskell/adt 916 2097152 1.09 .0000005197525024 4274998837 2038 3.9
rust/structs 707 2097152 1.42 .0000006771087646 5649657628 2693 4.0
cpp/novirtual 211 524288 1.01 .0000019264221191 3954019536 7541 3.9
java/Records n/a 524288 1.03 .0000019645690917 4016778710 7661 3.9
java/Objects n/a 524288 1.04 .0000019836425781 3981964797 7594 3.8
csharp/Structs n/a 524288 1.82 .0000034713745117 7202693322 13738 4.0
csharp/Objects n/a 524288 1.93 .0000036811828613 7498772724 14302 3.9
cpp/interpreter 2946 262144 1.23 .0000046920776367 4807527311 18339 3.9
cpp/functions_with_new 200 262144 1.38 .0000052642822265 5391530849 20567 3.9
cpp/lambdas 450 262144 1.87 .0000071334838867 7319503152 27921 3.9
cpp/objects 511 131072 1.44 .0000109863281250 5561337381 42429 3.9
go/structs n/a 131072 1.57 .0000119781494140 6250160223 47684 4.0
pascal/Objects n/a 32768 1.36 .0000415039062500 5364436062 163709 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.