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 125 2x
Rust rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) 0 3,606
C# 8.0.122 34 5,735 165x
Java javac 21.0.9 41 4,588 110x
Go go version go1.22.2 linux/amd64 39 15,822 401x
Pascal 3.2.2 58 32,780 556x
C++ Ubuntu clang version 18.1.3 (1ubuntu1) 93 7,274 77x

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 31695377 0 NaN
cpp/loop 115 268435456 1.57 .0000000058487057 6096198430 22 3.8
cpp/matrixes 165 134217728 1.35 .0000000100582838 5266977943 39 3.9
go/fast n/a 134217728 1.57 .0000000116974115 6110506181 45 3.8
cpp/binpow-matrix 160 67108864 1.35 .0000000201165676 5244759814 78 3.9
haskell/zipwith 985 4194304 1.41 .0000003361701965 5486468544 1308 3.9
haskell/iterate 906 4194304 1.42 .0000003385543823 5533721056 1319 3.9
haskell/object_dynamic 1113 2097152 1.04 .0000004959106445 3984242137 1899 3.8
haskell/tail_recursion 781 2097152 1.04 .0000004959106445 4070330506 1940 3.9
cpp/interpreter 2946 65536 1.12 .0000170898437500 4517232829 68927 4.0
cpp/inlines 68 256 1.51 .0058984375000000 5882469355 22978395 3.9
cpp/recursion 68 256 1.51 .0058984375000000 5876826143 22956352 3.9
cpp/static_member_functions 69 256 1.51 .0058984375000000 5848751511 22846685 3.9
csharp/Functions n/a 256 2.27 .0088671875000000 8871536785 34654440 3.9
csharp/Recursion n/a 256 2.27 .0088671875000000 8869926181 34648149 3.9
cpp/decorators 198 256 2.53 .0098828125000000 9854893087 38495676 3.9
go/recursion n/a 256 2.59 .0101171875000000 10090832173 39417313 3.9
java/Functions n/a 256 2.74 .0107031250000000 10673597910 41693741 3.9
java/Recursion n/a 256 2.74 .0107031250000000 10660336119 41641937 3.9
cpp/classes 82 256 2.85 .0111328125000000 11124578517 43455384 3.9
cpp/stack_objects 82 256 2.86 .0111718750000000 11134068264 43492454 3.9
pascal/recursion n/a 256 3.87 .0151171875000000 15089600521 58943752 3.9
haskell/recursion 786 256 3.90 .0152343750000000 15144089213 59156598 3.9
cpp/functions 86 256 6.16 .0240625000000000 23987691286 93701919 3.9
haskell/polymorphic_recursion 2092 256 6.88 .0268750000000000 26922011778 105164108 3.9
haskell/objects 968 256 8.03 .0313671875000000 32090040642 125351721 4.0
haskell/adt 916 256 17.64 .0689062500000000 68435188479 267324954 3.9
cpp/novirtual 211 256 88.40 .3453125000000000 345062149302 1347899020 3.9
cpp/functions_with_new 200 256 234.39 .9155859375000000 910077817671 3554991475 3.9
rust/structs 707 256 236.97 .9256640625000000 923188142504 3606203681 3.9
java/Records n/a 16 18.10 1.1312500000000000 70615493852 4413468365 3.9
java/Objects n/a 16 18.85 1.1781250000000000 73420032460 4588752028 3.9
cpp/lambdas 450 16 19.55 1.2218750000000000 77827574510 4864223406 4.0
csharp/Objects n/a 8 11.85 1.4812500000000000 45885783971 5735722996 3.9
csharp/Structs n/a 8 12.84 1.6050000000000000 49959382394 6244922799 3.9
cpp/objects 511 8 14.96 1.8700000000000000 58192821601 7274102700 3.9
go/structs n/a 4 16.24 4.0600000000000000 63291392445 15822848111 3.9
pascal/Objects n/a 2 16.76 8.3800000000000000 65560445682 32780222841 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 2025-12-19 by @yegor256 at "Linux ip-172-31-24-76 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.