/usr/share/doc/libbenchmark-ocaml-dev/examples/regexps.ml is in libbenchmark-ocaml-dev 1.3-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | open Printf
open Benchmark
(* Test the speed of standard regular expressions vs. Pcre using a
simple regexp with captures.
The output looks something like regexps.out
*)
(* Create a chunk of data to search.
It's full of "near hits", strings of "012345678"
with a string on the end we are searching for: "0123456789" *)
let bigdata =
let size = 500000 in
let buf = Buffer.create size in
for i = 1 to size/10 - 1 do Buffer.add_string buf "012345678 " done;
Buffer.add_string buf "0123456789";
Buffer.contents buf
let pcre_re = Pcre.regexp "(012345678) (0123456789)"
let str_re = Str.regexp "\\(012345678\\) \\(0123456789\\)"
let pcre_match dat =
let group = Pcre.extract ~rex:pcre_re dat in
(group.(1), group.(2))
let str_match dat =
let _pos = Str.search_forward str_re dat 0 in
(Str.matched_group 1 dat, Str.matched_group 2 dat)
let () =
(* Print out the results of the functions to doublecheck that they
work as we intend. *)
let (a, b) = pcre_match bigdata in printf "Pcre matches: %s %s\n" a b;
let (a, b) = str_match bigdata in printf "Str matches: %s %s\n" a b;
print_newline ();
let res = throughputN ~repeat:5 5
[("pcre match", pcre_match, bigdata);
("str match", str_match, bigdata)] in
print_newline();
tabulate res
(* print_newline(); *)
(* let res = latencyN ~repeat:5 100 *)
(* [("pcre match", pcre_match, bigdata); *)
(* ("str match", str_match, bigdata)] in *)
(* print_newline(); *)
(* tabulate res *)
|