diff --git a/Makefile b/Makefile index b60b806..f2ab6e3 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ all: ocamlbuild $(TARGETS) $(DOC) 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: ocamlbuild -use-ocamlfind -pkg oUnit tests/run_tests.native diff --git a/sequence.ml b/sequence.ml index d322fe3..32e3f22 100644 --- a/sequence.ml +++ b/sequence.ml @@ -184,7 +184,9 @@ module MList = struct let rec push x l = if l.len = Array.length l.content 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 end else begin (* insert in l *) l.content.(l.len) <- x; diff --git a/tests/simple_bench.ml b/tests/simple_bench.ml new file mode 100644 index 0000000..96611d7 --- /dev/null +++ b/tests/simple_bench.ml @@ -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); + ()