File: performance.ml

package info (click to toggle)
ocaml-sedlex 3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: ml: 7,866; makefile: 24; sh: 9
file content (23 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let rec token buf =
  match%sedlex buf with any -> token buf | eof -> () | _ -> assert false

let time f x =
  let rec acc f x = function
    | 0 -> f x
    | n ->
        f x |> ignore;
        acc f x (n - 1)
  in
  let t = Sys.time () in
  let fx = acc f x 10 in
  Printf.printf "Execution time: %fs\n" (Sys.time () -. t);
  fx

let () =
  let long_str = String.make 1000000 '\n' in
  let token_from _ =
    let lexbuf = Sedlexing.Latin1.from_string long_str in
    (* let () = Sedlexing.set_curr_p lexbuf Lexing.dummy_pos in *)
    token lexbuf
  in
  time token_from long_str