11open Lockfree
2- let num_elems = 200_000
3- let num_threads = 2
42
5- (* A write heavy workload with threads with 50% adds and 50% removes. *)
6- let write_heavy_workload () =
7- let sl = Atomicskiplist. create () in
8- (* let elems = Array.init num_elems (fun _ -> Random.int 10000) in *)
9- let push = (fun () -> Domain. spawn ( fun () ->
10- let start_time = Unix. gettimeofday () in
11- for i = 0 to (num_elems - 1 ) do (
12- if (i/ 2 ) < num_elems/ 2 then
13- Atomicskiplist. add sl (i) |> ignore
14- else
15- Atomicskiplist. remove sl (i - (num_elems/ 2 )) |> ignore)
16- done ;
17- start_time
18- )) in
19- let threads = List. init num_threads (fun _ -> push () ) in
20- let start_time_threads = List. map (fun domain -> Domain. join domain) threads in
21- let end_time = Unix. gettimeofday () in
22- let time_diff = end_time -. (List. nth start_time_threads 0 ) in
3+ let max_height = 10
4+
5+ let workload num_elems num_threads add remove =
6+ let sl = Atomicskiplist. create max_height in
7+ let elems = Array. init num_elems (fun _ -> Random. int 10000 ) in
8+ let push () =
9+ Domain. spawn (fun () ->
10+ let start_time = Unix. gettimeofday () in
11+ for i = 0 to (num_elems - 1 ) / num_threads do
12+ Domain. cpu_relax () ;
13+ let prob = Random. float 1.0 in
14+ if prob < add then Atomicskiplist. add sl (Random. int 10000 ) |> ignore
15+ else if prob > = add && prob < add +. remove then
16+ Atomicskiplist. remove sl (Random. int 10000 ) |> ignore
17+ else Atomicskiplist. mem sl elems.(i) |> ignore
18+ done ;
19+ start_time)
20+ in
21+ let threads = List. init num_threads (fun _ -> push () ) in
22+ let start_time_threads =
23+ List. map (fun domain -> Domain. join domain) threads
24+ in
25+ let end_time = Unix. gettimeofday () in
26+ let time_diff = end_time -. List. nth start_time_threads 0 in
2327 time_diff
2428
29+ (* A write heavy workload with threads with 50% adds and 50% removes. *)
30+ let write_heavy_workload num_elems num_threads =
31+ workload num_elems num_threads 0.5 0.5
32+
2533(* A regular workload with 90% reads, 9% adds and 1% removes. *)
34+ <<<<<<< HEAD
2635let read_heavy_workload () =
2736 let sl = Atomicskiplist. create () in
2837 let elems = Array. init num_elems (fun _ -> Random. int 10000 ) in
@@ -68,23 +77,41 @@ let read_heavy_workload () =
6877 let time_diff = end_time -. (List. nth start_time_threads 0 ) in
6978 time_diff
7079
80+ =======
81+ let read_heavy_workload num_elems num_threads =
82+ workload num_elems num_threads 0.09 0.01
83+
84+ let moderate_heavy_workload num_elems num_threads =
85+ workload num_elems num_threads 0.2 0.1
86+ >>>>>>> testing
7187
88+ let balanced_heavy_workload num_elems num_threads =
89+ workload num_elems num_threads 0.3 0.2
7290
73- let bench ~workload_type () =
91+ let bench ~workload_type ~ num_elems ~ num_threads () =
7492 let workload =
93+ <<<<<<< HEAD
7594 if workload_type = " read_heavy" then
7695 read_heavy_workload
7796 else if workload_type == " moderate_heavy" then
7897 moderate_heavy_workload
7998 else
8099 write_heavy_workload
81100 in
101+ =======
102+ if workload_type = " read_heavy" then read_heavy_workload
103+ else if workload_type = " moderate_heavy" then moderate_heavy_workload
104+ else if workload_type = " balanced_heavy" then balanced_heavy_workload
105+ else write_heavy_workload
106+ in
107+ >>>>>>> testing
82108 let results = ref [] in
83109 for i = 1 to 10 do
84- let time = workload () in
110+ let time = workload num_elems num_threads in
85111 if i > 1 then results := time :: ! results
86112 done ;
87113 let results = List. sort Float. compare ! results in
88114 let median_time = List. nth results 4 in
89115 let median_throughput = Float. of_int num_elems /. median_time in
90- Benchmark_result. create_generic ~median_time ~median_throughput (" atomic_skiplist_" ^ workload_type)
116+ Benchmark_result. create_generic ~median_time ~median_throughput
117+ (" atomic_skiplist_" ^ workload_type)
0 commit comments