forked from procub3r/RepCl.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.py
executable file
·60 lines (47 loc) · 1.58 KB
/
sim.py
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
#!/usr/bin/env python3
from repcl import RepCl
from veccl import VecCl
import random
import time
'''
This program compares the performance of
vector clocks and replay clocks
'''
PROC_COUNT = 32
VECCL_COUNTER_WIDTH = 64
REPCL_FIELD_WIDTH = 64
REPCL_INTERVAL = 1
REPCL_EPSILON = 1
repcl = [RepCl(i, REPCL_FIELD_WIDTH, 1, 1) for i in range(PROC_COUNT)]
veccl = [VecCl(i, PROC_COUNT, VECCL_COUNTER_WIDTH) for i in range(PROC_COUNT)]
while True:
proc_id = random.randint(0, PROC_COUNT - 1)
other_proc_id = random.randint(0, PROC_COUNT - 1)
repeat = 5_000
repcl_time = 0
veccl_time = 0
if proc_id == other_proc_id:
print('local: ', end='')
for i in range(repeat):
tmp_repcl = repcl[proc_id]
tmp_veccl = veccl[proc_id]
repcl_time += tmp_repcl.send_local()
veccl_time += tmp_veccl.advance()
else:
print('merge: ', end='')
for i in range(repeat):
tmp_repcl = repcl[proc_id]
tmp_veccl = veccl[proc_id]
repcl_time += tmp_repcl.recv(repcl[other_proc_id])
veccl_time += tmp_veccl.merge(veccl[other_proc_id])
print(f'RepCl: {repcl_time / repeat}, VecCl: {veccl_time / repeat}')
# timeVec = None
# timeRep = None
# # if proc_id == other_proc_id:
# timeRep = repcl[proc_id].send_local()
# timeVec = veccl[proc_id].advance()
# #else:
# # timeRep = repcl[proc_id].merge(repcl[other_proc_id])
# # timeVec = veccl[proc_id].merge(veccl[other_proc_id])
# print(f"RepCl: {timeRep}, VecCl: {timeVec}")
time.sleep(0.1)