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) 21 5,047 232x
C# 8.0.131 36 7,451 205x
Java javac 21.0.12.1 41 5,712 137x
Go go version go1.22.2 linux/amd64 39 19,812 500x
Pascal 3.2.2 63 34,173 539x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 98 7,364 74x

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.10 .0000000040978193 4279085650 15 3.7
java/LowLatency n/a 134217728 1.09 .0000000081211328 4300699305 32 3.9
cpp/matrixes 161 134217728 1.21 .0000000090152025 4727000529 35 3.9
go/fast n/a 134217728 1.56 .0000000116229057 6070295921 45 3.9
cpp/binpow-matrix 157 67108864 1.03 .0000000153481960 4038088016 60 3.9
haskell/zipwith 985 4194304 1.41 .0000003361701965 5493828181 1309 3.9
haskell/iterate 906 4194304 1.42 .0000003385543823 5490928642 1309 3.9
haskell/object_dynamic 1113 2097152 1.01 .0000004816055297 3936216310 1876 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4105797967 1957 3.9
cpp/interpreter 2945 65536 1.08 .0000164794921875 4262636631 65042 3.9
rust/recursion 607 256 1.43 .0055859375000000 5564952191 21738094 3.9
cpp/static_member_functions 71 256 1.77 .0069140625000000 6883695876 26889437 3.9
cpp/recursion 70 256 1.95 .0076171875000000 7634132546 29820830 3.9
cpp/inlines 70 256 1.96 .0076562500000000 7657886772 29913620 3.9
csharp/Functions n/a 256 2.38 .0092968750000000 9291392200 36294500 3.9
csharp/Recursion n/a 256 2.38 .0092968750000000 9339071458 36480747 3.9
cpp/decorators 198 256 2.54 .0099218750000000 9869746171 38553695 3.9
go/recursion n/a 256 2.60 .0101562500000000 10136683103 39596418 3.9
java/Functions n/a 256 2.74 .0107031250000000 10660414134 41642242 3.9
java/Recursion n/a 256 2.88 .0112500000000000 10661353392 41645911 3.7
cpp/classes 82 256 3.07 .0119921875000000 11978582901 46791339 3.9
cpp/stack_objects 82 256 3.07 .0119921875000000 11974573658 46775678 3.9
haskell/recursion 788 256 3.70 .0144531250000000 14408984544 56285095 3.9
pascal/recursion n/a 256 4.16 .0162500000000000 16214160333 63336563 3.9
cpp/functions 86 256 6.45 .0251953125000000 25138442899 98197042 3.9
haskell/polymorphic_recursion 2082 256 7.48 .0292187500000000 29080831820 113596999 3.9
haskell/objects 973 256 8.86 .0346093750000000 34525722527 134866103 3.9
haskell/adt 920 256 17.66 .0689843750000000 68807451771 268779108 3.9
cpp/novirtual 210 256 87.15 .3404296875000000 343674766479 1342479556 3.9
cpp/functions_with_new 201 256 231.82 .9055468750000000 903934338600 3530993510 3.9
cpp/lambdas 449 16 19.58 1.2237500000000000 76333882605 4770867662 3.9
rust/structs 708 16 20.64 1.2900000000000000 80763456054 5047716003 3.9
java/Objects n/a 8 11.78 1.4725000000000000 45696938456 5712117307 3.9
java/Records n/a 8 11.83 1.4787500000000000 46183513428 5772939178 3.9
cpp/objects 518 8 15.17 1.8962500000000000 58915280323 7364410040 3.9
csharp/Objects n/a 8 15.23 1.9037500000000000 59615588989 7451948623 3.9
csharp/Structs n/a 8 16.51 2.0637500000000000 64307839365 8038479920 3.9
go/structs n/a 4 20.42 5.1050000000000000 79248773194 19812193298 3.9
pascal/Objects n/a 2 17.41 8.7050000000000000 68347910306 34173955153 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-10-05 by @yegor256 at "Linux ip-172-31-22-158 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.