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 56 134 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 5,026
C# 8.0.126 36 7,436 204x
Java javac 21.0.10 41 5,715 137x
Go go version go1.22.2 linux/amd64 39 19,989 504x
Pascal 3.2.2 63 34,270 540x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 98 7,694 78x

This is what it takes to calculate the 32nd Fibonacci number using different algorithms:

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.00 0 23382303 0 NaN
cpp/loop 110 268435456 1.10 .0000000040978193 4280449056 15 3.7
java/LowLatency n/a 134217728 1.10 .0000000081956386 4285557217 31 3.8
cpp/matrixes 161 134217728 1.21 .0000000090152025 4725562595 35 3.9
go/fast n/a 134217728 1.56 .0000000116229057 6074170674 45 3.9
cpp/binpow-matrix 157 67108864 1.03 .0000000153481960 4036848683 60 3.9
haskell/iterate 906 4194304 1.41 .0000003361701965 5515370608 1314 3.9
haskell/zipwith 985 4194304 1.42 .0000003385543823 5462467815 1302 3.8
haskell/object_dynamic 1113 2097152 1.00 .0000004768371582 3908602777 1863 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4141633298 1974 3.9
cpp/interpreter 2945 65536 1.13 .0000172424316406 4558305851 69554 4.0
cpp/static_member_functions 71 256 1.77 .0069140625000000 6895644334 26936110 3.9
cpp/inlines 70 256 1.95 .0076171875000000 7274123832 28414546 3.7
cpp/recursion 70 256 1.96 .0076562500000000 7630083949 29805015 3.9
csharp/Recursion n/a 256 2.35 .0091796875000000 9307381586 36356959 4.0
csharp/Functions n/a 256 2.38 .0092968750000000 9308150237 36359961 3.9
cpp/decorators 198 256 2.55 .0099609375000000 9863998310 38531243 3.9
go/recursion n/a 256 2.61 .0101953125000000 10141552835 39615440 3.9
java/Functions n/a 256 2.74 .0107031250000000 10661873155 41647942 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10659664698 41639315 3.9
cpp/classes 82 256 3.07 .0119921875000000 11973840633 46772814 3.9
cpp/stack_objects 82 256 3.07 .0119921875000000 11973951490 46773248 3.9
haskell/recursion 788 256 3.70 .0144531250000000 14409695698 56287873 3.9
pascal/recursion n/a 256 4.16 .0162500000000000 16219339268 63356794 3.9
cpp/functions 86 256 6.44 .0251562500000000 25168767105 98315496 3.9
haskell/polymorphic_recursion 2082 256 8.10 .0316406250000000 29215098639 114121479 3.6
haskell/objects 973 256 8.87 .0346484375000000 34521621415 134850083 3.9
haskell/adt 920 256 17.85 .0697265625000000 69622109794 271961366 3.9
cpp/novirtual 210 256 90.30 .3527343750000000 352839298713 1378278510 3.9
cpp/functions_with_new 201 256 239.63 .9360546875000000 933037843486 3644679076 3.9
cpp/lambdas 449 16 20.51 1.2818750000000000 79976692238 4998543264 3.9
rust/structs 708 16 20.71 1.2943750000000000 80431355320 5026959707 3.9
java/Objects n/a 8 11.72 1.4650000000000000 45724302605 5715537825 3.9
java/Records n/a 8 11.85 1.4812500000000000 46194058843 5774257355 3.9
csharp/Objects n/a 8 15.24 1.9050000000000000 59488405192 7436050649 3.9
cpp/objects 518 8 15.77 1.9712500000000000 61554110299 7694263787 3.9
csharp/Structs n/a 8 16.47 2.0587500000000000 64160193620 8020024202 3.9
go/structs n/a 4 19.79 4.9475000000000000 79956350020 19989087505 4.0
pascal/Objects n/a 2 17.47 8.7350000000000000 68540877254 34270438627 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-05-18 by @yegor256 at "Linux ip-172-31-31-95 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.