optimized MList, with twice as fast insertion (on big tests);

see ./simple_bench.native 10_000_000. The optimization is based on increasing block size.
This commit is contained in:
Simon Cruanes 2013-03-11 00:54:28 +01:00
parent 0115102c2a
commit b946b7157b
3 changed files with 16 additions and 2 deletions

View file

@ -9,7 +9,8 @@ all:
ocamlbuild $(TARGETS) $(DOC) ocamlbuild $(TARGETS) $(DOC)
benchs: all benchs: all
ocamlbuild -use-ocamlfind -pkg bench -pkg unix tests/benchs.native ocamlbuild -use-ocamlfind -pkg bench -pkg unix tests/benchs.native \
tests/simple_bench.native
tests: tests:
ocamlbuild -use-ocamlfind -pkg oUnit tests/run_tests.native ocamlbuild -use-ocamlfind -pkg oUnit tests/run_tests.native

View file

@ -184,7 +184,9 @@ module MList = struct
let rec push x l = let rec push x l =
if l.len = Array.length l.content if l.len = Array.length l.content
then begin (* insert in the next block *) then begin (* insert in the next block *)
(if l.tl == _empty () then l.tl <- make (Array.length l.content)); (if l.tl == _empty () then
let n = Array.length l.content in
l.tl <- make (n + n lsr 1));
push x l.tl push x l.tl
end else begin (* insert in l *) end else begin (* insert in l *)
l.content.(l.len) <- x; l.content.(l.len) <- x;

11
tests/simple_bench.ml Normal file
View file

@ -0,0 +1,11 @@
open Sequence.Infix
let _ =
let n = int_of_string Sys.argv.(1) in
let seq = 0 -- n in
let start = Unix.gettimeofday () in
seq |> Sequence.persistent |> Sequence.fold (+) 0 |> ignore;
let stop = Unix.gettimeofday () in
Format.printf "iter on %d: %.4f@." n (stop -. start);
()