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 59 122 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 3,609
C# 8.0.125 34 5,708 164x
Java javac 21.0.10 41 4,596 110x
Go go version go1.22.2 linux/amd64 39 15,960 404x
Pascal 3.2.2 58 32,728 554x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,878 84x

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 31705883 0 NaN
cpp/loop 115 268435456 1.57 .0000000058487057 6100205378 22 3.8
cpp/matrixes 165 134217728 1.35 .0000000100582838 5269945013 39 3.9
go/fast n/a 134217728 1.57 .0000000116974115 6092160405 45 3.8
cpp/binpow-matrix 160 67108864 1.35 .0000000201165676 5249690616 78 3.9
haskell/zipwith 985 4194304 1.40 .0000003337860107 5443653700 1297 3.9
haskell/iterate 906 4194304 1.41 .0000003361701965 5549389860 1323 3.9
haskell/object_dynamic 1113 2097152 1.02 .0000004863739013 3965541618 1890 3.9
haskell/tail_recursion 781 2097152 1.05 .0000005006790161 4064332848 1938 3.9
cpp/interpreter 2946 65536 1.17 .0000178527832031 4523515688 69023 3.9
cpp/inlines 68 256 1.51 .0058984375000000 5882321396 22977817 3.9
cpp/static_member_functions 69 256 1.51 .0058984375000000 5867312116 22919187 3.9
cpp/recursion 68 256 1.59 .0062109375000000 5888745232 23002911 3.7
csharp/Functions n/a 256 2.26 .0088281250000000 8878352519 34681064 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8878874174 34683102 3.9
cpp/decorators 198 256 2.57 .0100390625000000 10291194175 40199977 4.0
go/recursion n/a 256 2.60 .0101562500000000 10100715407 39455919 3.9
java/Functions n/a 256 2.73 .0106640625000000 10664780059 41659297 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10661859470 41647888 3.9
cpp/classes 82 256 2.86 .0111718750000000 11129879683 43476092 3.9
cpp/stack_objects 82 256 2.88 .0112500000000000 11146403123 43540637 3.9
pascal/recursion n/a 256 3.88 .0151562500000000 15097236978 58973581 3.9
haskell/recursion 786 256 3.91 .0152734375000000 15164790935 59237464 3.9
cpp/functions 86 256 6.15 .0240234375000000 24005368040 93770968 3.9
haskell/polymorphic_recursion 2092 256 6.91 .0269921875000000 27675130523 108105978 4.0
haskell/objects 968 256 8.03 .0313671875000000 31283185432 122199943 3.9
haskell/adt 916 256 17.85 .0697265625000000 68868005880 269015647 3.9
cpp/novirtual 211 256 92.27 .3604296875000000 369753743779 1444350561 4.0
rust/structs 707 256 239.56 .9357812500000000 924121855323 3609850997 3.9
cpp/functions_with_new 200 256 239.78 .9366406250000000 934571110183 3650668399 3.9
java/Records n/a 16 18.09 1.1306250000000000 70479358233 4404959889 3.9
java/Objects n/a 16 18.87 1.1793750000000000 73542649862 4596415616 3.9
cpp/lambdas 450 16 21.63 1.3518750000000000 80420831584 5026301974 3.7
csharp/Objects n/a 8 11.75 1.4687500000000000 45671941062 5708992632 3.9
csharp/Structs n/a 8 12.81 1.6012500000000000 50003330820 6250416352 3.9
cpp/objects 511 8 16.51 2.0637500000000000 63025504781 7878188097 3.8
go/structs n/a 4 15.97 3.9925000000000000 63841800318 15960450079 4.0
pascal/Objects n/a 2 16.80 8.4000000000000000 65457419770 32728709885 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-03-31 by @yegor256 at "Linux ip-172-31-16-55 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.