Skip to content

Instantly share code, notes, and snippets.

@jdh30
Created May 9, 2019 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdh30/6a656f7f30144fb71f18b1278759a7c1 to your computer and use it in GitHub Desktop.
Save jdh30/6a656f7f30144fb71f18b1278759a7c1 to your computer and use it in GitHub Desktop.
Regular expression benchmark in F#
open System.Text.RegularExpressions
let str = System.IO.File.ReadAllText "C:\\Users\\Jon\\Documents\\pg10.txt"
let re = System.IO.File.ReadAllText "C:\\Users\\Jon\\Documents\\re.txt"
for _ in 1..3 do
let timer = System.Diagnostics.Stopwatch.StartNew()
let re = Regex(re, RegexOptions.Compiled)
let res = Array.Parallel.init 4 (fun _ -> re.Split str |> Seq.sumBy (fun m -> m.Length))
printfn "%A %fs" res timer.Elapsed.TotalSeconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment