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.115 0 1 94x
Java javac 21.0.7 0 0 51x
Go go version go1.22.2 linux/amd64 0 4 269x
Pascal 3.2.2 0 13 492x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 3 79x

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 1406465 0 NaN
cpp/loop 115 268435456 1.10 .0000000040978193 4308338177 16 3.9
go/fast n/a 268435456 1.96 .0000000073015689 7623593410 28 3.8
cpp/matrixes 165 134217728 1.17 .0000000087171792 4573754201 34 3.9
cpp/binpow-matrix 160 67108864 1.17 .0000000174343585 4575418898 68 3.9
haskell/zipwith 985 4194304 1.30 .0000003099441528 5096375392 1215 3.9
haskell/iterate 906 4194304 1.31 .0000003123283386 5126466256 1222 3.9
haskell/object_dynamic 1113 4194304 1.75 .0000004172325134 6814767974 1624 3.9
haskell/tail_recursion 781 4194304 1.77 .0000004220008850 6900141374 1645 3.9
cpp/static_member_functions 69 524288 1.37 .0000026130676269 5353657487 10211 3.9
cpp/recursion 68 524288 1.38 .0000026321411132 5399816134 10299 3.9
cpp/inlines 68 524288 1.39 .0000026512145996 5400166601 10300 3.9
csharp/Functions n/a 262144 1.05 .0000040054321289 4136723375 15780 3.9
csharp/Recursion n/a 262144 1.07 .0000040817260742 4132981233 15766 3.9
go/recursion n/a 262144 1.20 .0000045776367187 4679024353 17849 3.9
cpp/decorators 198 262144 1.26 .0000048065185546 4940424425 18846 3.9
java/Functions n/a 262144 1.27 .0000048446655273 4943415135 18857 3.9
java/Recursion n/a 262144 1.27 .0000048446655273 4951228463 18887 3.9
cpp/classes 82 262144 1.32 .0000050354003906 5161225991 19688 3.9
cpp/stack_objects 82 262144 1.33 .0000050735473632 5159459650 19681 3.9
pascal/recursion n/a 262144 1.79 .0000068283081054 6986569253 26651 3.9
haskell/recursion 786 262144 1.86 .0000070953369140 7278142274 27763 3.9
cpp/interpreter 2946 131072 1.20 .0000091552734375 4761645195 36328 4.0
cpp/functions 86 131072 1.43 .0000109100341796 5579454824 42567 3.9
haskell/polymorphic_recursion 2092 131072 1.69 .0000128936767578 6548689069 49962 3.9
haskell/objects 968 131072 1.94 .0000148010253906 7603311768 58008 3.9
haskell/adt 916 65536 1.25 .0000190734863281 4837067150 73807 3.9
rust/structs 707 8192 1.15 .0001403808593750 4572124991 558120 4.0
cpp/novirtual 211 8192 1.28 .0001562500000000 5042486021 615537 3.9
java/Records n/a 4096 1.00 .0002441406250000 3907420091 953959 3.9
java/Objects n/a 4096 1.02 .0002490234375000 3977024454 970953 3.9
csharp/Objects n/a 4096 1.56 .0003808593750000 6080654886 1484534 3.9
csharp/Structs n/a 4096 1.60 .0003906250000000 6314755761 1541688 3.9
cpp/functions_with_new 200 4096 1.70 .0004150390625000 6686273112 1632390 3.9
cpp/lambdas 450 2048 1.14 .0005566406250000 4433747287 2164915 3.9
cpp/objects 511 2048 1.73 .0008447265625000 6902967759 3370589 4.0
go/structs n/a 1024 1.23 .0012011718750000 4918992615 4803703 4.0
pascal/Objects n/a 512 1.72 .0033593750000000 6714416075 13114093 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.