mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 03:05:29 -05:00
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:
parent
0115102c2a
commit
b946b7157b
3 changed files with 16 additions and 2 deletions
3
Makefile
3
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
11
tests/simple_bench.ml
Normal file
11
tests/simple_bench.ml
Normal 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);
|
||||
()
|
||||
Loading…
Add table
Reference in a new issue