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.122 0 1 94x
Java javac 21.0.9 0 0 51x
Go go version go1.22.2 linux/amd64 0 4 264x
Pascal 3.2.2 0 13 490x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 3 77x

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 1470653 0 NaN
cpp/loop 115 268435456 1.10 .0000000040978193 4310558407 16 3.9
go/fast n/a 268435456 1.97 .0000000073388218 7614289040 28 3.8
cpp/matrixes 165 134217728 1.17 .0000000087171792 4575678729 34 3.9
cpp/binpow-matrix 160 67108864 1.17 .0000000174343585 4575382729 68 3.9
haskell/zipwith 985 4194304 1.30 .0000003099441528 5112073510 1218 3.9
haskell/iterate 906 4194304 1.32 .0000003147125244 5127547154 1222 3.9
haskell/object_dynamic 1113 4194304 1.76 .0000004196166992 6949462808 1656 3.9
haskell/tail_recursion 781 4194304 1.76 .0000004196166992 6888454728 1642 3.9
cpp/recursion 68 524288 1.38 .0000026321411132 5404166051 10307 3.9
cpp/static_member_functions 69 524288 1.38 .0000026321411132 5355194034 10214 3.9
cpp/inlines 68 524288 1.39 .0000026512145996 5405454682 10310 3.9
csharp/Functions n/a 262144 1.05 .0000040054321289 4136501339 15779 3.9
csharp/Recursion n/a 262144 1.05 .0000040054321289 4142568630 15802 3.9
go/recursion n/a 262144 1.20 .0000045776367187 4681980989 17860 3.9
java/Functions n/a 262144 1.27 .0000048446655273 4943681337 18858 3.9
java/Recursion n/a 262144 1.27 .0000048446655273 4947542473 18873 3.9
cpp/decorators 198 262144 1.30 .0000049591064453 4931099053 18810 3.8
cpp/classes 82 262144 1.32 .0000050354003906 5159452048 19681 3.9
cpp/stack_objects 82 262144 1.32 .0000050354003906 5164282592 19700 3.9
pascal/recursion n/a 262144 1.79 .0000068283081054 6993442059 26677 3.9
haskell/recursion 786 262144 1.85 .0000070571899414 7284838669 27789 3.9
cpp/interpreter 2946 131072 1.21 .0000092315673828 4691110074 35790 3.9
cpp/functions 86 131072 1.42 .0000108337402343 5566503478 42469 3.9
haskell/polymorphic_recursion 2092 131072 1.68 .0000128173828125 6522976486 49766 3.9
haskell/objects 968 131072 1.95 .0000148773193359 7598055734 57968 3.9
haskell/adt 916 65536 1.27 .0000193786621093 4834805576 73773 3.8
rust/structs 707 8192 1.16 .0001416015625000 4507569153 550240 3.9
cpp/novirtual 211 8192 1.28 .0001562500000000 5009795240 611547 3.9
java/Records n/a 8192 1.92 .0002343750000000 7469751396 911834 3.9
java/Objects n/a 4096 1.02 .0002490234375000 3958374593 966400 3.9
csharp/Objects n/a 4096 1.55 .0003784179687500 6090632958 1486970 3.9
csharp/Structs n/a 4096 1.60 .0003906250000000 6262879763 1529023 3.9
cpp/functions_with_new 200 4096 1.71 .0004174804687500 6612648793 1614416 3.9
cpp/lambdas 450 2048 1.13 .0005517578125000 4420186178 2158294 3.9
cpp/objects 511 2048 1.73 .0008447265625000 6760697647 3301121 3.9
go/structs n/a 1024 1.19 .0011621093750000 4842270232 4728779 4.1
pascal/Objects n/a 512 1.72 .0033593750000000 6702301279 13090432 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.