add CCFQueue to benchmarks

This commit is contained in:
Simon Cruanes 2015-08-31 18:47:10 +02:00
parent 944c85167f
commit f50776f70f

View file

@ -12,8 +12,6 @@ let app_ints f l = B.Tree.concat (List.map (app_int f) l)
(* composition *) (* composition *)
let (%%) f g x = f (g x) let (%%) f g x = f (g x)
(* FIXME: find out why -tree takes so long *)
module L = struct module L = struct
(* FLAT MAP *) (* FLAT MAP *)
@ -580,7 +578,21 @@ module Batch = struct
end end
module Deque = struct module Deque = struct
module Base = struct module type DEQUE = sig
type 'a t
val create : unit -> 'a t
val of_seq : 'a Sequence.t -> 'a t
val iter : ('a -> unit) -> 'a t -> unit
val push_front : 'a t -> 'a -> unit
val push_back : 'a t -> 'a -> unit
val is_empty : 'a t -> bool
val take_front : 'a t -> 'a
val take_back : 'a t -> 'a
val append_back : into:'a t -> 'a t -> unit
val length : _ t -> int
end
module Base : DEQUE = struct
type 'a elt = { type 'a elt = {
content : 'a; content : 'a;
mutable prev : 'a elt; mutable prev : 'a elt;
@ -670,22 +682,30 @@ module Deque = struct
!n !n
end end
module type DEQUE = sig module FQueue : DEQUE = struct
type 'a t type 'a t = 'a CCFQueue.t ref
val create : unit -> 'a t let create () = ref CCFQueue.empty
val of_seq : 'a Sequence.t -> 'a t let of_seq s = ref (CCFQueue.of_seq s)
val iter : ('a -> unit) -> 'a t -> unit let iter f q = CCFQueue.iter f !q
val push_front : 'a t -> 'a -> unit let push_front q x = q:= CCFQueue.cons x !q
val push_back : 'a t -> 'a -> unit let push_back q x = q:= CCFQueue.snoc !q x
val is_empty : 'a t -> bool let is_empty q = CCFQueue.is_empty !q
val take_front : 'a t -> 'a let take_front q =
val take_back : 'a t -> 'a let x, q' = CCFQueue.take_front_exn !q in
val append_back : into:'a t -> 'a t -> unit q := q';
val length : _ t -> int x
let take_back q =
let q', x = CCFQueue.take_back_exn !q in
q := q';
x
let append_back ~into q = into := CCFQueue.append !into !q
let length q = CCFQueue.size !q
end end
let base = (module Base : DEQUE) let base = (module Base : DEQUE)
let cur = (module CCDeque : DEQUE) let cur = (module CCDeque : DEQUE)
let fqueue = (module FQueue : DEQUE)
let bench_iter n = let bench_iter n =
let seq = Sequence.(1 -- n) in let seq = Sequence.(1 -- n) in
@ -699,6 +719,7 @@ module Deque = struct
B.throughputN 3 B.throughputN 3
[ "base", make base, () [ "base", make base, ()
; "cur", make cur, () ; "cur", make cur, ()
; "fqueue", make fqueue, ()
] ]
let bench_push_front n = let bench_push_front n =
@ -709,6 +730,7 @@ module Deque = struct
B.throughputN 3 B.throughputN 3
[ "base", make base, () [ "base", make base, ()
; "cur", make cur, () ; "cur", make cur, ()
; "fqueue", make fqueue, ()
] ]
let bench_push_back n = let bench_push_back n =
@ -720,6 +742,7 @@ module Deque = struct
B.throughputN 3 B.throughputN 3
[ "base", make base, () [ "base", make base, ()
; "cur", make cur, () ; "cur", make cur, ()
; "fqueue", make fqueue, ()
] ]
let bench_append n = let bench_append n =
@ -732,6 +755,7 @@ module Deque = struct
B.throughputN 3 B.throughputN 3
[ "base", make base, () [ "base", make base, ()
; "cur", make cur, () ; "cur", make cur, ()
; "fqueue", make fqueue, ()
] ]
let bench_length n = let bench_length n =
@ -743,6 +767,7 @@ module Deque = struct
B.throughputN 3 B.throughputN 3
[ "base", make base, () [ "base", make base, ()
; "cur", make cur, () ; "cur", make cur, ()
; "fqueue", make fqueue, ()
] ]
let () = B.Tree.register ( let () = B.Tree.register (