-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tas.ml
101 lines (88 loc) · 2.72 KB
/
test_tas.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
open Taslock
let mean ?(cut_minmax = 0) data =
let data = List.sort compare data in
let length = List.length data in
if cut_minmax * 2 > length then failwith "Not enougth data";
let data =
List.filteri (fun i _ -> i >= cut_minmax && i <= length - cut_minmax) data
in
let sum = List.fold_left (fun curr_sum b -> curr_sum +. b) 0. data in
let n = Int.to_float (List.length data) in
sum /. n
let print ~gnuplot res =
if gnuplot then
let n_domains = List.hd res |> snd |> List.map fst in
let nlines = List.length n_domains in
let names, lines =
List.fold_left
(fun (names, acc) (name, res) ->
( names ^ name ^ "\t",
List.map2
(fun tmp (_, mean) -> tmp ^ "\t" ^ Float.to_string mean)
acc res ))
("ndomains\t", List.init nlines (fun _ -> ""))
res
in
let lines =
names
:: List.map2 (fun line nd -> Int.to_string nd ^ line) lines n_domains
in
List.iter (Format.printf "%s@.") lines
else
List.iter
(fun (name, means) ->
Format.printf "%s : @." name;
List.iter
(fun (ndomain, mean) ->
Format.printf " for ndomain= %d : %f.6@." ndomain mean)
means)
res
(* This test is here to compare a TAS lock performances with or without backoff*)
let test_taslock ?(gnuplot = false) () =
let test (module Lock : LOCK) ndomain nlock rounds =
let orch = Orchestrator.init ~total_domains:ndomain ~rounds in
let counter = ref 0 in
let lock = Lock.create () in
let incr () =
Lock.acquire lock;
incr counter;
Lock.release lock
in
let domains =
List.init ndomain (fun _ ->
Domain.spawn (fun () ->
Orchestrator.worker orch (fun () ->
for _ = 0 to nlock - 1 do
incr ()
done)))
in
let res = Orchestrator.run orch in
List.iter Domain.join domains;
res
in
let nlock, nround = (10_000, 100) in
let all_lock =
[
("TAS-lock", (module TASlock : LOCK));
("TTAS-lock", (module TTASlock));
("TTAS-lock-with-backoff", (module TTASlock_boff));
]
in
let res =
List.map
(fun (name, (module Lock : LOCK)) ->
( name,
(List.map (fun ndomain ->
let data = test (module Lock) ndomain nlock nround in
Gc.major ();
let mean = mean ~cut_minmax:(nround / 20) data in
(ndomain, mean)))
[ 1; 2; 3; 4; 5; 6; 7 ] ))
all_lock
in
print ~gnuplot res
let _ = test_taslock ~gnuplot:true ()
(*
dune exec ./bench/test_taslock.exe > bench.data
gnuplot -p -e 'plot for [col=2:4] "bench.data" using 1:col with lines title columnheader'
*)