Skip to content

Commit 2a82404

Browse files
committed
Code Review changes
2 parents fb49543 + 24e39c4 commit 2a82404

File tree

8 files changed

+349
-361
lines changed

8 files changed

+349
-361
lines changed

bench/bench_atomic_skiplist.ml

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
open 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
2635
let 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)

bench/main.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ let benchmark_list =
1616
Mpmc_queue.bench ~use_cas:true ~takers:4 ~pushers:4;
1717
Mpmc_queue.bench ~use_cas:true ~takers:1 ~pushers:8;
1818
Mpmc_queue.bench ~use_cas:true ~takers:8 ~pushers:1;
19+
<<<<<<< HEAD
1920
Bench_atomic_skiplist.bench ~workload_type:"read_heavy";
2021
Bench_atomic_skiplist.bench ~workload_type:"moderate_heavy";
22+
=======
23+
Bench_atomic_skiplist.bench ~workload_type:"read_heavy" ~num_elems:2000000
24+
~num_threads:2;
25+
Bench_atomic_skiplist.bench ~workload_type:"moderate_heavy"
26+
~num_elems:2000000 ~num_threads:2;
27+
>>>>>>> testing
2128
]
2229
@ backoff_benchmarks
2330

0 commit comments

Comments
 (0)