The Computer Language
Benchmarks Game

regex-redux F# .NET Core #5 program

source code

// The Computer Language Benchmarks Game
// http://benchmarksgame.alioth.debian.org/
//
// regex-dna program contributed by David Grenier
// converted from regex-dna program
// parallelization by Peter Kese

open System.Text.RegularExpressions
open Microsoft.FSharp.Collections

let regex s = Regex (s, RegexOptions.Compiled)
let input = stdin.ReadToEnd ()
let text = (regex ">.*\n|\n").Replace (input, "")

let matchTasks = 
    [   "agggtaaa|tttaccct"
        "[cgt]gggtaaa|tttaccc[acg]"
        "a[act]ggtaaa|tttacc[agt]t"
        "ag[act]gtaaa|tttac[agt]ct"
        "agg[act]taaa|ttta[agt]cct"
        "aggg[acg]aaa|ttt[cgt]ccct"
        "agggt[cgt]aa|tt[acg]accct"
        "agggta[cgt]a|t[acg]taccct"
        "agggtaa[cgt]|[acg]ttaccct"]
    |> List.map (fun pattern () ->
        ((regex pattern).Matches text).Count
            |> sprintf "%s %i\n" pattern) 

let replaceTask () =
    [
        "tHa[Nt]", "<4>"
        "aND|caN|Ha[DS]|WaS", "<3>"
        "a[NSt]|BY", "<2>"
        "<[^>]*>", "|"
        "\\|[^|][^|]*\\|","-"]
    |> List.fold (fun s (pattern, replace) -> 
        (regex pattern).Replace (s, replace)) text
    |> String.length
    |> sprintf "\n%i\n%i\n%i\n" input.Length text.Length

replaceTask :: (matchTasks |> List.rev )
|> List.toArray
|> Array.Parallel.map (fun task -> task ())
|> Array.rev
|> Array.iter (printf "%s")
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
2.0.0 cdcd1928c9
"System.GC.Server": true


Mon, 14 Aug 2017 23:27:28 GMT

MAKE:
cp regexredux.fsharpcore-5.fsharpcore Program.fs
cp Include/fsharpcore/tmp.fsproj .
cp Include/fsharpcore/runtimeconfig.template.json .
mkdir obj
cp Include/fsharpcore/project.assets.json ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.props ./obj
cp Include/fsharpcore/tmp.fsproj.nuget.g.targets ./obj
/usr/bin/dotnet build -c Release
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  tmp -> /home/dunham/benchmarksgame_quadcore/regexredux/tmp/bin/Release/netcoreapp2.0/tmp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:08.93

11.52s to complete and log all make actions

COMMAND LINE:
/usr/bin/dotnet ./bin/Release/netcoreapp2.0/tmp.dll 0 < regexredux-input5000000.txt

PROGRAM OUTPUT:
agggtaaa|tttaccct 356
[cgt]gggtaaa|tttaccc[acg] 1250
a[act]ggtaaa|tttacc[agt]t 4252
ag[act]gtaaa|tttac[agt]ct 2894
agg[act]taaa|ttta[agt]cct 5435
aggg[acg]aaa|ttt[cgt]ccct 1537
agggt[cgt]aa|tt[acg]accct 1431
agggta[cgt]a|t[acg]taccct 1608
agggtaa[cgt]|[acg]ttaccct 2178

50833411
50000000
27388361