Skip to content

Instantly share code, notes, and snippets.

@edwintorok
Created December 1, 2024 18:14
Show Gist options
  • Save edwintorok/6845d6f980f54cc10f43aa1b6ebab5a2 to your computer and use it in GitHub Desktop.
Save edwintorok/6845d6f980f54cc10f43aa1b6ebab5a2 to your computer and use it in GitHub Desktop.
(* Generated by re2ocaml 4.0 on Sat Nov 30 16:34:14 2024 *)
open String
let rec yy0 (yyinput:string) (yymarker:int) (yycursor: int) : bool =
let yych = get yyinput yycursor in
let yycursor = yycursor + 1 in
match yych with
| '0'..'9' -> (yy3 [@tailcall]) yyinput yymarker yycursor
| _ -> (yy1 [@tailcall]) yyinput yymarker yycursor
and yy1 (yyinput : string) (yymarker : int) (yycursor:int): bool =
(yy2 [@tailcall]) yyinput yymarker yycursor
and yy2 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
false
and yy3 (yyinput : string) (yymarker : int) (yycursor: int) : bool =
let yymarker = yycursor in
let yych = get yyinput yycursor in
match yych with
| '\n' ->
let yycursor = yycursor + 1 in
(yy4 [@tailcall]) yyinput yymarker yycursor
| '0'..'9' ->
let yycursor = yycursor + 1 in
(yy5 [@tailcall]) yyinput yymarker yycursor
| _ -> (yy2 [@tailcall]) yyinput yymarker yycursor
and yy4 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
true
and yy5 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
let yych = get yyinput yycursor in
match yych with
| '\n' ->
let yycursor = yycursor + 1 in
(yy4 [@tailcall]) yyinput yymarker yycursor
| '0'..'9' ->
let yycursor = yycursor + 1 in
(yy5 [@tailcall]) yyinput yymarker yycursor
| _ -> (yy6 [@tailcall]) yyinput yymarker yycursor
and yy6 (yyinput : string) (yymarker : int) (yycursor: int) : bool =
let yycursor = yymarker in
(yy2 [@tailcall]) yyinput yymarker yycursor
and lex (yyinput : string) (yymarker : int) (yycursor:int) : bool =
(yy0 [@tailcall]) yyinput yymarker yycursor
let lex (yyinput : string) : bool =
(lex[@tailcall]) yyinput 0 0
let main () =
let s = "1234567890\n" in
(* let st = {yyinput = s; yycursor = 0; yymarker = 0}
in if not (lex st) then raise (Failure "error"); *)
for i = 1 to (10 * 1000 * 1000) do
ignore (Sys.opaque_identity (lex s))
done
let _ = main ()
(* Generated by re2ocaml 4.0 on Sat Nov 30 16:34:14 2024 *)
open String
type state = {
yyinput: string;
mutable yymarker: int;
}
let rec yy0 (yyrecord : state) (yycursor: int): bool =
let yych = get yyrecord.yyinput yycursor in
let yycursor = yycursor + 1 in
match yych with
| '0'..'9' -> (yy3 [@tailcall]) yyrecord yycursor
| _ -> (yy1 [@tailcall]) yyrecord yycursor
and yy1 (yyrecord : state) (yycursor : int): bool =
(yy2 [@tailcall]) yyrecord yycursor
and yy2 (yyrecord : state) (yycursor : int) : bool =
false
and yy3 (yyrecord : state) (yycursor:int): bool =
yyrecord.yymarker <- yycursor;
let yych = get yyrecord.yyinput yycursor in
match yych with
| '\n' ->
let yycursor = yycursor + 1 in
(yy4 [@tailcall]) yyrecord yycursor
| '0'..'9' ->
let yycursor = yycursor + 1 in
(yy5 [@tailcall]) yyrecord yycursor
| _ -> (yy2 [@tailcall]) yyrecord yycursor
and yy4 (yyrecord : state) (yycursor: int): bool =
true
and yy5 (yyrecord : state) (yycursor: int): bool =
let yych = get yyrecord.yyinput yycursor in
match yych with
| '\n' ->
let yycursor = yycursor + 1 in
(yy4 [@tailcall]) yyrecord yycursor
| '0'..'9' ->
let yycursor = yycursor + 1 in
(yy5 [@tailcall]) yyrecord yycursor
| _ -> (yy6 [@tailcall]) yyrecord yycursor
and yy6 (yyrecord : state) (yycursor: int): bool =
let yycursor = yyrecord.yymarker in
(yy2 [@tailcall]) yyrecord yycursor
and lex (yyrecord : state) (yycursor: int): bool =
(yy0 [@tailcall]) yyrecord yycursor
let lex (yyrecord: state): bool =
lex yyrecord 0
let main () =
let s = "1234567890\n" in
(* let st = {yyinput = s; yycursor = 0; yymarker = 0}
in if not (lex st) then raise (Failure "error"); *)
for i = 1 to (10 * 1000 * 1000) do
let st = {yyinput = s; yymarker = 0}
in ignore (lex st)
done
let _ = main ()
@edwintorok
Copy link
Author

edwintorok commented Dec 1, 2024

yyargs_compat.ml

(* Generated by re2ocaml 4.0 on Sat Nov 30 16:34:14 2024 *)
open String

type state = {
    yyinput: string;
    mutable yycursor: int;
    mutable yymarker: int;
}

let rec yy0 (yyrecord : state) (yyinput:string) (yycursor: int) : bool =
    let yych = get yyinput yycursor in
    let yycursor = yycursor + 1 in
    match yych with
        | '0'..'9' -> (yy3 [@tailcall]) yyrecord yyinput yycursor
        | _ -> (yy1 [@tailcall]) yyrecord yyinput yycursor

and yy1 (yyrecord : state) (yyinput : string) (yycursor:int): bool =
    (yy2 [@tailcall]) yyrecord yyinput yycursor

and yy2 (yyrecord : state) (yyinput : string) (yycursor:int) : bool =
    yyrecord.yycursor <- yycursor;
    false

and yy3 (yyrecord : state) (yyinput : string) (yycursor: int) : bool =
    yyrecord.yymarker <- yycursor;
    let yych = get yyinput yycursor in
    match yych with
        | '\n' ->
            let yycursor = yycursor + 1 in
            (yy4 [@tailcall]) yyrecord yyinput yycursor
        | '0'..'9' ->
            let yycursor = yycursor + 1 in
            (yy5 [@tailcall]) yyrecord yyinput yycursor
        | _ -> (yy2 [@tailcall]) yyrecord yyinput yycursor

and yy4 (yyrecord: state) (yyinput : string) (yycursor:int) : bool =
    yyrecord.yycursor <- yycursor;
    true

and yy5 (yyrecord : state) (yyinput : string) (yycursor:int) : bool =
    let yych = get yyinput yycursor in
    match yych with
        | '\n' ->
            let yycursor = yycursor + 1 in
            (yy4 [@tailcall]) yyrecord yyinput yycursor
        | '0'..'9' ->
            let yycursor = yycursor + 1 in
            (yy5 [@tailcall]) yyrecord yyinput yycursor
        | _ -> (yy6 [@tailcall]) yyrecord yyinput yycursor

and yy6 (yyrecord:state) (yyinput : string) (yycursor: int) : bool =
    let yycursor = yyrecord.yymarker in
    (yy2 [@tailcall]) yyrecord yyinput yycursor

let lex (yyrecord: state) : bool =
    (yy0 [@tailcall]) yyrecord yyrecord.yyinput yyrecord.yycursor

let main () =
    let s = "1234567890\n" in

    (* let st = {yyinput = s; yycursor = 0; yymarker = 0}
       in if not (lex st) then raise (Failure "error"); *)
    for i = 1 to (10 * 1000 * 1000) do
      let st = {yyinput = s; yycursor = 0; yymarker = 0}
      in ignore (Sys.opaque_identity (lex st))
    done

let _ = main ()

@edwintorok
Copy link
Author

edwintorok commented Dec 1, 2024

yyargs_unsafe.ml:

(* Generated by re2ocaml 4.0 on Sat Nov 30 16:34:14 2024 *)
let get = String.unsafe_get

let rec yy0 (yyinput:string) (yymarker:int) (yycursor: int) : bool =
    let yych = get yyinput yycursor in
    let yycursor = yycursor + 1 in
    match yych with
        | '0'..'9' -> (yy3 [@tailcall]) yyinput yymarker yycursor
        | _ -> (yy1 [@tailcall]) yyinput yymarker yycursor

and yy1 (yyinput : string) (yymarker : int) (yycursor:int): bool =
    (yy2 [@tailcall]) yyinput yymarker yycursor

and yy2 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
    false

and yy3 (yyinput : string) (yymarker : int) (yycursor: int) : bool =
    let yymarker = yycursor in
    let yych = get yyinput yycursor in
    match yych with
        | '\n' ->
            let yycursor = yycursor + 1 in
            (yy4 [@tailcall]) yyinput yymarker yycursor
        | '0'..'9' ->
            let yycursor = yycursor + 1 in
            (yy5 [@tailcall]) yyinput yymarker yycursor
        | _ -> (yy2 [@tailcall]) yyinput yymarker yycursor

and yy4 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
    true

and yy5 (yyinput : string) (yymarker : int) (yycursor:int) : bool =
    let yych = get yyinput yycursor in
    match yych with
        | '\n' ->
            let yycursor = yycursor + 1 in
            (yy4 [@tailcall]) yyinput yymarker yycursor
        | '0'..'9' ->
            let yycursor = yycursor + 1 in
            (yy5 [@tailcall]) yyinput yymarker yycursor
        | _ -> (yy6 [@tailcall]) yyinput yymarker yycursor

and yy6 (yyinput : string) (yymarker : int) (yycursor: int) : bool =
    let yycursor = yymarker in
    (yy2 [@tailcall]) yyinput yymarker yycursor

and lex (yyinput : string) (yymarker : int) (yycursor:int) : bool =
    (yy0 [@tailcall]) yyinput yymarker yycursor

let lex (yyinput : string) : bool =
    (lex[@tailcall]) yyinput 0 0

let main () =
    let s = "1234567890\n" in

    (* let st = {yyinput = s; yycursor = 0; yymarker = 0}
       in if not (lex st) then raise (Failure "error"); *)
    for i = 1 to (10 * 1000 * 1000) do
      ignore (Sys.opaque_identity (lex s))
    done

let _ = main ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment