The Computer Language
25.02 Benchmarks Game

OCaml versus F#

How the programs are written matters! Always look at the source code.

If the fastest programs are flagged * possible hand-written vector instructions or "unsafe" or naked ffi, does the host language matter? You might be more interested in the less optimised programs — more seconds, less gz source code.

fannkuch-redux      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
F# #6 8.37 32.48 41,243 1103 13.16
OCaml #3 8.84 35.17 36,123 1024 1.50
OCaml #4 9.14 36.47 11,338 1018 1.53
F# #5 9.75 38.47—38.98 46,322 927 12.19
OCaml #2 45.79 45.79 4,784 478 1.42
OCaml 51.28 51.29—51.36 4,796 529 1.52
F# 149.70 111.07—115.04 46,936 558 12.12
n-body      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* F# #6 5.01 5.00 43,221 1395 17.01
* F# #5 5.85 5.86 43,524 1363 15.40
F# #4 6.95 6.93 43,553 1296 12.46
OCaml 6.95 6.95 4,043 1255 1.33
F# #3 6.99 6.97 41,685 1624 13.55
F# #2 7.36 7.35 43,639 1387 12.75
F# 8.77 8.03—8.08 46,506 1272 12.23
spectral-norm      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* F# #6 0.95 3.33—3.44 47,010 697 15.15
OCaml #2 5.34 5.34 6,074 383 1.46
F# #2 1.59 2.41—6.07 44,683 864 12.01
F# #4 1.60 5.86 46,375 738 11.38
mandelbrot      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* F# #6 4.18 16.28—16.45 77,173 943 14.24
* F# 4.42 17.24—17.42 77,042 890 14.07
F# #2 7.17 28.10—28.29 49,979 1054 12.10
OCaml #6 28.79 28.77—28.84 4,776 450 1.44
OCaml 7.60 30.21—30.25 64,643 723 1.52
fasta      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
OCaml #6 3.37 3.37 208,892 1194 1.43
F# #3 1.16 4.07 58,302 1361 12.17
OCaml #3 4.72 4.73 4,764 1075 1.52
F# #4 1.48 5.50—5.61 66,576 1355 12.35
k-nucleotide      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
F# #6 3.77 11.89—12.02 200,847 1913 12.63
F# #5 4.74 16.10—16.34 213,168 1964 12.97
F# #2 4.75 16.17—16.28 212,804 1932 12.62
F# #3 13.00 28.91—29.45 1,357,251 1124 12.67
F# #4 11.38 29.66—30.72 1,356,919 1522 12.66
* OCaml #3 16.17 43.00—44.11 286,568 1839 1.50
* OCaml 45.59 45.90—46.62 348,320 894 1.40
* OCaml #2 27.23 61.90—62.14 363,422 1247 1.96
F# 39.58 92.39—94.04 932,966 713 12.15
reverse-complement      
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* OCaml 2.27 5.29—5.46 1,519,079 1372 1.50
OCaml #3 2.28 5.88—6.08 1,518,805 1361 1.64
OCaml #2 9.29 9.30—9.36 933,937 426 1.42
F# 41.59 43.03—43.44 3,088,159 603 12.36
F# #4   Timed Out  
F# #5   Timed Out  
binary-trees      [ Contentious. Different approaches. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
OCaml #5 7.78 7.80 228,925 468 1.29
OCaml #2 3.55 10.39—10.51 868,213 759 1.45
F# 14.36 15.26—15.61 938,693 517 13.10
F# #7 8.98 23.05—23.86 1,127,907 527 12.31
pidigits      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* F# #6 0.84 0.83 40,571 917 12.37
* F# #4 1.32 1.34 41,902 887 13.65
OCaml #5 2.77 2.78 9,834 465 1.53
OCaml #7   Empty  
regex-redux      [ Contentious. Different libraries. ]
  elapsed Mean or 95% CI      
source secs cpu secs mem gz make
* OCaml #3 2.20 3.38 469,848 653 1.75
F# #2 4.81 5.03 879,477 437 11.89
F# #6 1.81 5.23—5.44 787,112 622 12.16
F# #7 5.59 6.65—6.73 686,174 610 12.14
* OCaml #2 14.01 14.04 947,642 644 1.60
F#   Bad Output  
F# #4   Bad Output  
OCaml

OCaml native-code
5.4.0+dev0-2024-08-25

F#

.NET SDK 9.0.100
Host Version: 9.0.0
Commit: 9d5a6a9aa4

<OutputType>Exe
<TargetFramework>net9.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>false