This is what it takes to calculate the 32th Fibonacci number using different algorithms:
Program | ASM | Cycles | Time | SPC | Ticks | TPC | GHz |
---|---|---|---|---|---|---|---|
go/fast | n/a | 33554432 | 1.07 | .0000000318884849 | 3884785485 | 115 | 3.6 |
cpp/loop | 73 | 16777216 | 1.24 | .0000000739097595 | 4458949373 | 265 | 3.6 |
cpp/formula | 197 | 8388608 | 1.70 | .0000002026557922 | 6122820225 | 729 | 3.6 |
haskell/zipwith | 1172 | 2097152 | 1.05 | .0000005006790161 | 3746184990 | 1786 | 3.6 |
cpp/binpow-matrix | 326 | 2097152 | 1.75 | .0000008344650268 | 6397243713 | 3050 | 3.7 |
haskell/iterate | 1195 | 1048576 | 1.65 | .0000015735626220 | 5595793250 | 5336 | 3.4 |
haskell/tail_recursion | 1226 | 524288 | 1.50 | .0000028610229492 | 5412116135 | 10322 | 3.6 |
cpp/matrixes | 463 | 262144 | 1.07 | .0000040817260742 | 3929302813 | 14989 | 3.7 |
haskell/object_dynamic | 1302 | 262144 | 1.79 | .0000068283081054 | 6194310938 | 23629 | 3.5 |
cpp/interpreter | 3125 | 8192 | 1.89 | .0002307128906250 | 6630889303 | 809434 | 3.5 |
java/Recursion | n/a | 256 | 3.55 | .0138671875000000 | 12627210646 | 49325041 | 3.6 |
go/recursion | n/a | 256 | 5.04 | .0196875000000000 | 16500964293 | 64456891 | 3.3 |
cpp/recursion | 72 | 256 | 5.57 | .0217578125000000 | 19965043683 | 77988451 | 3.6 |
pascal/recursion | n/a | 256 | 6.43 | .0251171875000000 | 23133420087 | 90364922 | 3.6 |
cpp/decorators | 366 | 256 | 6.50 | .0253906250000000 | 23689139563 | 92535701 | 3.6 |
ada/recursion | n/a | 256 | 7.92 | .0309375000000000 | 28847692428 | 112686298 | 3.6 |
java/Functions | n/a | 256 | 8.35 | .0326171875000000 | 30248468868 | 118158081 | 3.6 |
rust/recursion | 3998 | 256 | 9.54 | .0372656250000000 | 34570318254 | 135040305 | 3.6 |
cpp/inlines | 107 | 256 | 14.75 | .0576171875000000 | 52913177508 | 206692099 | 3.6 |
cpp/functions | 116 | 256 | 14.76 | .0576562500000000 | 53047377262 | 207216317 | 3.6 |
cpp/static_member_functions | 116 | 256 | 15.04 | .0587500000000000 | 53785213373 | 210098489 | 3.6 |
lisp/recursion | n/a | 256 | 17.30 | .0675781250000000 | 62178193527 | 242883568 | 3.6 |
cpp/classes | 186 | 256 | 38.39 | .1499609375000000 | 137496994045 | 537097632 | 3.6 |
cpp/stack_objects | 173 | 256 | 49.31 | .1926171875000000 | 175159526706 | 684216901 | 3.6 |
haskell/recursion | 1208 | 256 | 50.17 | .1959765625000000 | 196390691369 | 767151138 | 3.9 |
haskell/adt | 1314 | 256 | 94.62 | .3696093750000000 | 357756780509 | 1397487423 | 3.8 |
haskell/objects | 1325 | 16 | 19.73 | 1.2331250000000000 | 70856899688 | 4428556230 | 3.6 |
rust/structs | 4164 | 8 | 12.66 | 1.5825000000000000 | 45472349173 | 5684043646 | 3.6 |
java/Objects | n/a | 8 | 15.12 | 1.8900000000000000 | 54106302517 | 6763287814 | 3.6 |
haskell/polymorphic_recursion | 2253 | 8 | 16.48 | 2.0600000000000000 | 61763515383 | 7720439422 | 3.7 |
go/structs | n/a | 4 | 20.74 | 5.1850000000000000 | 81348702338 | 20337175584 | 3.9 |
pascal/Objects | n/a | 2 | 20.31 | 10.1550000000000000 | 76199385946 | 38099692973 | 3.8 |
cpp/functions_with_new | 269 | 1 | 16.64 | 16.6400000000000000 | 59339081163 | 59339081163 | 3.6 |
cpp/lambdas | 309 | 1 | 21.19 | 21.1900000000000000 | 74621529742 | 74621529742 | 3.5 |
cpp/objects | 898 | 1 | 23.79 | 23.7900000000000000 | 86306496098 | 86306496098 | 3.6 |
cpp/novirtual | 419 | 1 | 152.95 | 152.9500000000000000 | 544414284349 | 544414284349 | 3.6 |
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.
Optimization is disabled 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.
Built on 2022-03-18 by @yegor256 at "Linux x3.0dmx.com 4.15.0-118-generic #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux" machine.