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,053 232x
C# 8.0.127 36 7,447 205x
Java javac 21.0.11 41 5,712 137x
Go go version go1.22.2 linux/amd64 39 19,756 499x
Pascal 3.2.2 63 34,259 540x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 98 7,878 80x

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 4281507228 15 3.7
java/LowLatency n/a 134217728 1.09 .0000000081211328 4333365529 32 3.9
cpp/matrixes 161 134217728 1.21 .0000000090152025 4724668056 35 3.9
go/fast n/a 134217728 1.56 .0000000116229057 6065601664 45 3.9
cpp/binpow-matrix 157 67108864 1.03 .0000000153481960 4035271961 60 3.9
haskell/zipwith 985 4194304 1.41 .0000003361701965 5444560795 1298 3.9
haskell/iterate 906 4194304 1.42 .0000003385543823 5485418285 1307 3.9
haskell/object_dynamic 1113 2097152 1.01 .0000004816055297 3924014768 1871 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4132069590 1970 3.9
cpp/interpreter 2945 65536 1.13 .0000172424316406 4389649125 66980 3.9
rust/recursion 607 256 1.43 .0055859375000000 5562258796 21727573 3.9
cpp/static_member_functions 71 256 1.77 .0069140625000000 6882220062 26883672 3.9
cpp/inlines 70 256 1.95 .0076171875000000 7639039755 29839999 3.9
cpp/recursion 70 256 1.96 .0076562500000000 7626934038 29792711 3.9
csharp/Functions n/a 256 2.38 .0092968750000000 9285295479 36270685 3.9
csharp/Recursion n/a 256 2.38 .0092968750000000 9316042584 36390791 3.9
go/recursion n/a 256 2.61 .0101953125000000 10127995792 39562483 3.9
cpp/decorators 198 256 2.69 .0105078125000000 11495682076 44905008 4.3
java/Functions n/a 256 2.73 .0106640625000000 10655893668 41624584 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10654989420 41621052 3.9
cpp/classes 82 256 3.07 .0119921875000000 11963132514 46730986 3.9
cpp/stack_objects 82 256 3.07 .0119921875000000 11963126848 46730964 3.9
haskell/recursion 788 256 3.70 .0144531250000000 14409713521 56287943 3.9
pascal/recursion n/a 256 4.16 .0162500000000000 16239838251 63436868 3.9
cpp/functions 86 256 6.46 .0252343750000000 25118801674 98120319 3.9
haskell/polymorphic_recursion 2082 256 7.50 .0292968750000000 31510358852 123087339 4.2
haskell/objects 973 256 8.89 .0347265625000000 34470630918 134650902 3.9
haskell/adt 920 256 17.83 .0696484375000000 69096369569 269907693 3.9
cpp/novirtual 210 256 90.70 .3542968750000000 352612152306 1377391219 3.9
cpp/functions_with_new 201 256 239.92 .9371875000000000 933106619891 3644947733 3.9
rust/structs 708 16 20.71 1.2943750000000000 80848198849 5053012428 3.9
cpp/lambdas 449 16 20.84 1.3025000000000000 81724605025 5107787814 3.9
java/Objects n/a 8 11.72 1.4650000000000000 45697240531 5712155066 3.9
java/Records n/a 8 11.85 1.4812500000000000 46192024094 5774003011 3.9
csharp/Objects n/a 8 15.24 1.9050000000000000 59582713502 7447839187 3.9
cpp/objects 518 8 15.94 1.9925000000000000 63029073409 7878634176 4.0
csharp/Structs n/a 8 16.31 2.0387500000000000 63964402603 7995550325 3.9
go/structs n/a 4 20.35 5.0875000000000000 79024651239 19756162809 3.9
pascal/Objects n/a 2 17.46 8.7300000000000000 68518978539 34259489269 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-08 by @yegor256 at "Linux ip-172-31-31-193 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.