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 141 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 21 5,089 234x
C# 8.0.128 36 7,412 203x
Java javac 21.0.11 41 5,718 137x
Go go version go1.22.2 linux/amd64 39 19,528 493x
Pascal 3.2.2 63 34,162 539x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 98 8,053 81x

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

Program ASM Cycles Time SPC Ticks TPC GHz
cpp/loop 110 268435456 1.13 .0000000042095780 4285539785 15 3.6
java/LowLatency n/a 134217728 1.10 .0000000081956386 4296634304 32 3.9
cpp/matrixes 161 134217728 1.25 .0000000093132257 4737375475 35 3.8
go/fast n/a 134217728 1.55 .0000000115483999 6073764717 45 3.9
cpp/binpow-matrix 157 67108864 1.03 .0000000153481960 4036618938 60 3.9
haskell/iterate 906 4194304 1.41 .0000003361701965 5610090467 1337 4.0
haskell/zipwith 985 4194304 1.41 .0000003361701965 5489789015 1308 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 3946658667 1881 3.9
haskell/tail_recursion 781 2097152 1.04 .0000004959106445 4188463478 1997 4.0
cpp/interpreter 2945 65536 1.24 .0000189208984375 4586092317 69978 3.7
rust/recursion 607 256 1.43 .0055859375000000 5567373843 21747554 3.9
cpp/static_member_functions 71 256 1.76 .0068750000000000 6881834834 26882167 3.9
cpp/recursion 70 256 1.96 .0076562500000000 7635893430 29827708 3.9
cpp/inlines 70 256 1.98 .0077343750000000 7653512406 29896532 3.9
csharp/Recursion n/a 256 2.37 .0092578125000000 9322788208 36417141 3.9
csharp/Functions n/a 256 2.38 .0092968750000000 9313130134 36379414 3.9
cpp/decorators 198 256 2.55 .0099609375000000 9872526686 38564557 3.9
go/recursion n/a 256 2.61 .0101953125000000 10136324863 39595018 3.9
java/Recursion n/a 256 2.73 .0106640625000000 10659588883 41639019 3.9
java/Functions n/a 256 2.74 .0107031250000000 10658743609 41635717 3.9
cpp/classes 82 256 3.07 .0119921875000000 11967638747 46748588 3.9
cpp/stack_objects 82 256 3.07 .0119921875000000 11974276671 46774518 3.9
haskell/recursion 788 256 3.71 .0144921875000000 14420401562 56329693 3.9
pascal/recursion n/a 256 4.16 .0162500000000000 16209180907 63317112 3.9
cpp/functions 86 256 6.45 .0251953125000000 25147217909 98231319 3.9
haskell/polymorphic_recursion 2082 256 7.47 .0291796875000000 31824680476 124315158 4.3
haskell/objects 973 256 8.86 .0346093750000000 36187279311 141356559 4.1
haskell/adt 920 256 17.75 .0693359375000000 68651444148 268169703 3.9
cpp/novirtual 210 256 97.44 .3806250000000000 372893098931 1456613667 3.8
cpp/functions_with_new 201 256 239.36 .9350000000000000 939712910307 3670753555 3.9
rust/structs 708 16 20.75 1.2968750000000000 81426510919 5089156932 3.9
cpp/lambdas 449 16 21.01 1.3131250000000000 80069367963 5004335497 3.8
java/Objects n/a 8 11.75 1.4687500000000000 45744026455 5718003306 3.9
java/Records n/a 8 11.90 1.4875000000000000 46266545314 5783318164 3.9
csharp/Objects n/a 8 15.25 1.9062500000000000 59300814337 7412601792 3.9
cpp/objects 518 8 16.37 2.0462500000000000 64427997881 8053499735 3.9
csharp/Structs n/a 8 16.49 2.0612500000000000 64033982724 8004247840 3.9
go/structs n/a 4 20.48 5.1200000000000000 78112999327 19528249831 3.8
pascal/Objects n/a 2 17.44 8.7200000000000000 68324613313 34162306656 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-06-14 by @yegor256 at "Linux ip-172-31-23-248 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.