The Computer Language
Benchmarks Game

regex-redux TypeScript #3 program

source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   by Josh Goldfoot, adapted from the node.js version
   compile with tsc --lib es7 regexredux.ts
*/

/// <reference path="./Include/node/index.d.ts" />

var fs = require("fs");

var i = fs.readFileSync("/dev/stdin", "ascii");
var ilen = i.length;
i = i.replace(/^>.*\n|\n/mg, "");
var clen = i.length;

var iubReplaceLen: Promise<number> = new Promise<number>(resolve => {
    var iub: string[] = ["-", "|", "<2>", "<3>", "<4>"];
    var iubR: RegExp[] = [/\|[^|][^|]*\|/g, /<[^>]*>/g, /a[NSt]|BY/g, 
        /aND|caN|Ha[DS]|WaS/g, /tHa[Nt]/g];
    var seq = i + "";
    while (iub.length)
        seq = seq.replace(iubR.pop(), iub.pop())
    resolve(seq.length);
});
    
var q: RegExp[] = [/agggtaaa|tttaccct/ig, /[cgt]gggtaaa|tttaccc[acg]/ig,
    /a[act]ggtaaa|tttacc[agt]t/ig, /ag[act]gtaaa|tttac[agt]ct/ig,
    /agg[act]taaa|ttta[agt]cct/ig, /aggg[acg]aaa|ttt[cgt]ccct/ig,
    /agggt[cgt]aa|tt[acg]accct/ig, /agggta[cgt]a|t[acg]taccct/ig,
    /agggtaa[cgt]|[acg]ttaccct/ig];

var promises: Promise<string>[] = q.map(r => new Promise<string>(resolve => {
    var m: RegExpMatchArray = i.match(r);
    resolve(r.source + " " + (m ? m.length : 0));
}));

async function displayOutput(promises: Promise<string>[], ilen: number,
        clen: number, iubReplaceLen: Promise<number>): Promise<void> {
    for (var count = 0; count < 9; count++)
        console.log(await promises[count]);

    console.log();
    console.log(ilen);
    console.log(clen);
    console.log(await iubReplaceLen);
}

displayOutput(promises, ilen, clen, iubReplaceLen);
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Version 2.6.1
node.js v9.0.0


Tue, 31 Oct 2017 23:58:48 GMT

MAKE:
mv regexredux.typescript-3.typescript regexredux.typescript-3.ts
/opt/src/node-v9.0.0-linux-x64/bin/tsc --alwaysStrict -t ESNEXT --lib es7 regexredux.typescript-3.ts

1.34s to complete and log all make actions

COMMAND LINE:
/opt/src/node-v9.0.0-linux-x64/bin/node --use_strict regexredux.typescript-3.js 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