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 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 0
C# 8.0.126 0 1 105x
Java javac 21.0.10 0 1 56x
Go go version go1.22.2 linux/amd64 0 5 295x
Pascal 3.2.2 0 12 451x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 3 78x

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

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.00 0 1432364 0 NaN
cpp/loop 110 536870912 1.38 .0000000025704503 5380004914 10 3.9
java/LowLatency n/a 268435456 1.96 .0000000073015689 7659217266 28 3.8
go/fast n/a 268435456 1.97 .0000000073388218 7641922741 28 3.8
cpp/matrixes 161 134217728 1.03 .0000000076740980 4012126338 29 3.8
cpp/binpow-matrix 157 134217728 1.74 .0000000129640102 6801303620 50 3.9
haskell/zipwith 985 4194304 1.30 .0000003099441528 5131432075 1223 3.9
haskell/iterate 906 4194304 1.32 .0000003147125244 5122430359 1221 3.9
haskell/object_dynamic 1113 4194304 1.71 .0000004076957702 6750085560 1609 3.9
haskell/tail_recursion 781 4194304 1.77 .0000004220008850 6915917488 1648 3.9
cpp/static_member_functions 71 524288 1.62 .0000030899047851 6312377042 12039 3.9
cpp/recursion 70 524288 1.80 .0000034332275390 7029501976 13407 3.9
cpp/inlines 70 524288 1.81 .0000034523010253 7023880997 13396 3.9
csharp/Functions n/a 262144 1.10 .0000041961669921 4337682868 16546 3.9
csharp/Recursion n/a 262144 1.13 .0000043106079101 4454440319 16992 3.9
go/recursion n/a 262144 1.20 .0000045776367187 4694128904 17906 3.9
java/Functions n/a 262144 1.27 .0000048446655273 4942412235 18853 3.9
java/Recursion n/a 262144 1.27 .0000048446655273 4942518493 18854 3.9
cpp/decorators 198 262144 1.28 .0000048828125000 4951491331 18888 3.9
cpp/classes 82 262144 1.42 .0000054168701171 5545601823 21154 3.9
cpp/stack_objects 82 262144 1.42 .0000054168701171 5545554776 21154 3.9
haskell/recursion 788 262144 1.78 .0000067901611328 6903384041 26334 3.9
pascal/recursion n/a 262144 1.93 .0000073623657226 7522965719 28697 3.9
cpp/interpreter 2945 131072 1.22 .0000093078613281 4606530516 35145 3.8
cpp/functions 86 131072 1.49 .0000113677978515 5821399202 44413 3.9
haskell/polymorphic_recursion 2082 131072 1.97 .0000150299072265 7135988845 54443 3.6
haskell/objects 973 65536 1.09 .0000166320800781 4208226690 64212 3.9
haskell/adt 920 65536 1.28 .0000195312500000 5060211228 77212 4.0
cpp/novirtual 210 8192 1.31 .0001599121093750 5129490320 626158 3.9
rust/structs 708 8192 1.62 .0001977539062500 6297776309 768771 3.9
java/Objects n/a 4096 1.13 .0002758789062500 4401046423 1074474 3.9
java/Records n/a 4096 1.16 .0002832031250000 4383318116 1070146 3.8
cpp/functions_with_new 201 4096 1.74 .0004248046875000 6832430220 1668073 3.9
csharp/Objects n/a 4096 1.81 .0004418945312500 7121466536 1738639 3.9
csharp/Structs n/a 4096 1.89 .0004614257812500 7393341430 1805014 3.9
cpp/lambdas 449 2048 1.19 .0005810546875000 4641048065 2266136 3.9
cpp/objects 518 2048 1.85 .0009033203125000 7141914664 3487263 3.9
go/structs n/a 1024 1.38 .0013476562500000 5426014705 5298842 3.9
pascal/Objects n/a 512 1.70 .0033203125000000 6629203571 12947663 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-04-25 by @yegor256 at "Linux ip-172-31-17-119 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.