performance measurements

Each table row shows performance measurements for this OCaml program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
50,0000.160.17?1502  0% 0% 6% 100%
500,0001.651.67294,7081502  0% 1% 2% 100%
5,000,000Failed  1502   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read regex-dna benchmark to see what this program should do.


The OCaml native-code compiler, version 4.02.1

 regex-dna OCaml program source code

(* The Computer Language Benchmarks Game
 * Contributed by Christophe TROESTLER
 * Parallelized by Jon Harrop
 * Modified by Mauricio Fernandez

open Printf

(* semi-standard function for process-based parallelism *)
let invoke (f : 'a -> 'b) x : unit -> 'b =
  let input, output = Unix.pipe() in
  match Unix.fork() with
  | -1 -> Unix.close input; Unix.close output; (let v = f x in fun () -> v)
  | 0 ->
      Unix.close input;
      let output = Unix.out_channel_of_descr output in
        Marshal.to_channel output (try `Res(f x) with e -> `Exn e) [];
        close_out output;
        exit 0
  | pid ->
      Unix.close output;
      let input = Unix.in_channel_of_descr input in fun () ->
        let v = Marshal.from_channel input in
        ignore (Unix.waitpid [] pid);
        close_in input;
        match v with `Res x -> x | `Exn e -> raise e

(* This module is a workaround for a bug in the Str library from the Ocaml
 * distribution used in the Computer Language Benchmarks Game. It can be removed
 * altogether when using OCaml 3.11 *)
module Str =
  include Str

  let substitute_first expr repl_fun text =
      let pos = Str.search_forward expr text 0 in
      String.concat "" [Str.string_before text pos;
                        repl_fun text;
                        Str.string_after text (Str.match_end())]
    with Not_found ->

  let opt_search_forward re s pos =
    try Some(Str.search_forward re s pos) with Not_found -> None

  let global_substitute expr repl_fun text =
    let rec replace accu start last_was_empty =
      let startpos = if last_was_empty then start + 1 else start in
      if startpos > String.length text then
        Str.string_after text start :: accu
        match opt_search_forward expr text startpos with
        | None ->
            Str.string_after text start :: accu
        | Some pos ->
            let end_pos = Str.match_end() in
            let repl_text = repl_fun text in
            replace (repl_text :: String.sub text start (pos-start) :: accu)
                    end_pos (end_pos = pos)
      String.concat "" (List.rev (replace [] 0 false))

  let global_replace expr repl text =
    global_substitute expr (Str.replace_matched repl) text
  and replace_first expr repl text =
    substitute_first expr (Str.replace_matched repl) text

let variants = ["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";

(* Remove the "\\" which is mandatory in OCaml regex. *)
let re_bs = Str.regexp_string "\\"
let to_string = Str.global_replace re_bs ""

let subst = ["B", "(c|g|t)"; "D", "(a|g|t)";   "H", "(a|c|t)"; "K", "(g|t)";
             "M", "(a|c)";   "N", "(a|c|g|t)"; "R", "(a|g)";   "S", "(c|g)";
             "V", "(a|c|g)"; "W", "(a|t)";     "Y", "(c|t)"]

(* Read all of a redirected FASTA format file from stdin. *)
let file_data, file_length =
  let b = Buffer.create 0xFFFF and s = String.create 0xFFF and r = ref 1 in
  while !r > 0 do
    r := input stdin s 0 0xFFF;   Buffer.add_substring b s 0 !r
  Buffer.contents b, Buffer.length b

(* Remove FASTA sequence descriptions and all linefeed characters.  *)
let dna = Str.global_replace (Str.regexp "^>.*$\\|\n") "" file_data
let code_length = String.length dna

(* Count matches of [re]. *)
let count re s =
  let re = Str.regexp_case_fold re and i = ref 0 and n = ref 0 in
    while true do i := 1 + Str.search_forward re s !i; incr n done; assert false
  with Not_found -> !n

let () =
  List.iter (fun f -> print_endline(f()))
	  (fun re -> sprintf "%s %i" (to_string re) (count re dna)))
  let b = ref dna in
  List.iter (fun (re, s) ->
               b := Str.global_replace (Str.regexp_case_fold re) s !b) subst;
  printf "\n%i\n%i\n%i\n" file_length code_length (String.length !b)

 make, command-line, and program output logs

Mon, 16 Mar 2015 03:30:44 GMT

mv regexdna.ocaml
/usr/local/bin/ocamlopt -noassert -unsafe -nodynlink -inline 100 unix.cmxa str.cmxa -o regexdna.ocaml_run
File "", line 88, characters 39-52:
Warning 3: deprecated: String.create
Use Bytes.create instead.
0.51s to complete and log all make actions

./regexdna.ocaml_run 0 < regexdna-input5000000.txt



Fatal error: exception Failure("Buffer.add: cannot grow buffer")

Revised BSD license

  Home   Conclusions   License   Play