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 0 0 1x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 0
C# 8.0.126 0 0 71x
Java javac 21.0.10 0 0 33x
Go go version go1.22.2 linux/amd64 0 0 216x
Pascal 3.2.2 0 0 433x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 0 0 80x

This is what it takes to calculate the 7th Fibonacci number using different algorithms:

Program ASM Cycles Time SPC Ticks TPC GHz
rust/recursion 602 MAX 0.00 0 1470376 0 NaN
java/LowLatency n/a 268435456 1.37 .0000000051036477 5303134686 19 3.7
go/fast n/a 268435456 1.58 .0000000058859586 6142915710 22 3.7
cpp/loop 110 268435456 1.86 .0000000069290399 7260799928 27 3.9
cpp/matrixes 161 268435456 1.86 .0000000069290399 7261416317 27 3.9
cpp/binpow-matrix 157 134217728 1.77 .0000000131875276 6891609175 51 3.9
cpp/static_member_functions 71 33554432 1.28 .0000000381469726 4983040896 148 3.9
cpp/inlines 70 33554432 1.37 .0000000408291816 5346850577 159 3.9
cpp/recursion 70 33554432 1.37 .0000000408291816 5345496235 159 3.9
csharp/Recursion n/a 33554432 1.87 .0000000557303428 7340987735 218 3.9
csharp/Functions n/a 33554432 1.90 .0000000566244125 7423500272 221 3.9
go/recursion n/a 33554432 1.98 .0000000590085983 7713953648 229 3.9
java/Functions n/a 16777216 1.03 .0000000613927841 3999597925 238 3.9
java/Recursion n/a 16777216 1.03 .0000000613927841 4006530324 238 3.9
cpp/classes 82 16777216 1.14 .0000000679492950 4459614456 265 3.9
cpp/stack_objects 82 16777216 1.14 .0000000679492950 4459597600 265 3.9
pascal/recursion n/a 16777216 1.56 .0000000929832458 6087470431 362 3.9
cpp/functions 86 8388608 1.22 .0000001454353332 4761265688 567 3.9
cpp/decorators 198 8388608 1.76 .0000002098083496 6591081614 785 3.7
haskell/zipwith 985 4194304 1.25 .0000002980232238 4909079581 1170 3.9
haskell/iterate 906 4194304 1.26 .0000003004074096 4941123939 1178 3.9
haskell/tail_recursion 781 4194304 1.41 .0000003361701965 5521064452 1316 3.9
haskell/object_dynamic 1113 4194304 1.42 .0000003385543823 5582134266 1330 3.9
haskell/recursion 788 4194304 1.60 .0000003814697265 6270881830 1495 3.9
haskell/polymorphic_recursion 2082 4194304 2.02 .0000004816055297 7805523958 1860 3.9
haskell/objects 973 2097152 1.04 .0000004959106445 4038643404 1925 3.9
haskell/adt 920 2097152 1.11 .0000005292892456 4333742264 2066 3.9
rust/structs 708 2097152 1.95 .0000009298324584 7597703632 3622 3.9
cpp/novirtual 210 524288 1.03 .0000019645690917 4066964139 7757 3.9
java/Objects n/a 524288 1.08 .0000020599365234 4221226313 8051 3.9
java/Records n/a 524288 1.08 .0000020599365234 4217647242 8044 3.9
csharp/Structs n/a 262144 1.00 .0000038146972656 3959221807 15103 4.0
csharp/Objects n/a 262144 1.05 .0000040054321289 4124074061 15732 3.9
cpp/interpreter 2945 262144 1.14 .0000043487548828 4488236002 17121 3.9
cpp/functions_with_new 201 262144 1.41 .0000053787231445 5510174248 21019 3.9
cpp/lambdas 449 262144 1.96 .0000074768066406 7622320981 29076 3.9
cpp/objects 518 131072 1.50 .0000114440917968 5957932027 45455 4.0
go/structs n/a 131072 1.64 .0000125122070312 6490303029 49517 4.0
pascal/Objects n/a 32768 1.33 .0000405883789062 5141731637 156913 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.