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,063
C# 8.0.126 36 7,426 204x
Java javac 21.0.10 41 5,711 137x
Go go version go1.22.2 linux/amd64 39 20,017 506x
Pascal 3.2.2 63 34,198 540x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 98 7,668 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 23188575 0 NaN
cpp/loop 110 268435456 1.09 .0000000040605664 4276800052 15 3.7
java/LowLatency n/a 134217728 1.10 .0000000081956386 4273686347 31 3.8
cpp/matrixes 161 134217728 1.21 .0000000090152025 4724027983 35 3.9
go/fast n/a 134217728 1.55 .0000000115483999 6069772137 45 3.9
cpp/binpow-matrix 157 67108864 1.03 .0000000153481960 4036036847 60 3.9
haskell/zipwith 985 4194304 1.40 .0000003337860107 5510972049 1313 3.9
haskell/iterate 906 4194304 1.44 .0000003433227539 5587577022 1332 3.9
haskell/object_dynamic 1113 2097152 1.01 .0000004816055297 3946811003 1881 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4116762985 1963 3.9
cpp/interpreter 2945 65536 1.13 .0000172424316406 4434919395 67671 3.9
cpp/static_member_functions 71 256 1.77 .0069140625000000 6874339289 26852887 3.9
cpp/inlines 70 256 1.96 .0076562500000000 7617701621 29756646 3.9
cpp/recursion 70 256 1.96 .0076562500000000 7626702428 29791806 3.9
csharp/Functions n/a 256 2.38 .0092968750000000 9296657646 36315068 3.9
csharp/Recursion n/a 256 2.38 .0092968750000000 9302059415 36336169 3.9
cpp/decorators 198 256 2.54 .0099218750000000 9945884926 38851112 3.9
go/recursion n/a 256 2.61 .0101953125000000 10127013911 39558648 3.9
java/Functions n/a 256 2.73 .0106640625000000 10651712956 41608253 3.9
java/Recursion n/a 256 2.73 .0106640625000000 10658303273 41633997 3.9
cpp/classes 82 256 3.07 .0119921875000000 11962922697 46730166 3.9
cpp/stack_objects 82 256 3.07 .0119921875000000 11963905309 46734005 3.9
haskell/recursion 788 256 3.70 .0144531250000000 14396280416 56235470 3.9
pascal/recursion n/a 256 4.17 .0162890625000000 16199012505 63277392 3.9
cpp/functions 86 256 6.45 .0251953125000000 25119880321 98124532 3.9
haskell/polymorphic_recursion 2082 256 8.08 .0315625000000000 31507918246 123077805 3.9
haskell/objects 973 256 9.01 .0351953125000000 34559486136 134997992 3.8
haskell/adt 920 256 17.72 .0692187500000000 70214299024 274274605 4.0
cpp/novirtual 210 256 91.49 .3573828125000000 352632768282 1377471751 3.9
cpp/functions_with_new 201 256 239.72 .9364062500000000 932812262880 3643797901 3.9
rust/structs 708 16 20.62 1.2887500000000000 81018437738 5063652358 3.9
cpp/lambdas 449 16 20.66 1.2912500000000000 79992920156 4999557509 3.9
java/Objects n/a 8 11.75 1.4687500000000000 45693894534 5711736816 3.9
java/Records n/a 8 11.89 1.4862500000000000 46119112390 5764889048 3.9
csharp/Objects n/a 8 15.23 1.9037500000000000 59413637983 7426704747 3.9
cpp/objects 518 8 15.78 1.9725000000000000 61347892364 7668486545 3.9
csharp/Structs n/a 8 16.47 2.0587500000000000 64045452046 8005681505 3.9
go/structs n/a 4 20.00 5.0000000000000000 80071093224 20017773306 4.0
pascal/Objects n/a 2 17.44 8.7200000000000000 68396287568 34198143784 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.