Skip to content

Instantly share code, notes, and snippets.

@alainfrisch
alainfrisch / after.ml
Created January 30, 2018 10:29
Optimizing "ocamllex -ml"
let rec __ocaml_lex_refill_buf lexbuf _buf _len _curr _last =
if lexbuf.Lexing.lex_eof_reached then
256, _buf, _len, _curr, _last
else begin
lexbuf.Lexing.lex_curr_pos <- _curr;
lexbuf.Lexing.lex_last_pos <- _last;
lexbuf.Lexing.refill_buff lexbuf;
let _curr = lexbuf.Lexing.lex_curr_pos in
let _last = lexbuf.Lexing.lex_last_pos in
@alainfrisch
alainfrisch / bench_set.ml
Last active March 8, 2017 12:31
bench_set
let cmps = ref 0
module I = Set.Make(struct
type t = int
let compare (x : t) y = incr cmps; compare x y
end)
let test n =
let i0 = 10000000 in
let rec mk a i =
@alainfrisch
alainfrisch / bench_filter_list_array.ml
Created November 2, 2016 15:34
Compare performance of filtering on list and arrays in OCaml
let rec loop a f len n i =
if i < len then
let x = Array.unsafe_get a i in
if f x then begin
let res = loop a f len (n + 1) (i + 1) in
Array.unsafe_set res n x;
res
end else
loop a f len n (i + 1)
else