Skip to content

Commit a8fd5c3

Browse files
committed
implement dummy uuid comparison
1 parent 91656c2 commit a8fd5c3

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

src/bench.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import math
2+
import zlib
3+
from random import choices
4+
from uuid import uuid4
5+
6+
from py_markdown_table.markdown_table import markdown_table
7+
8+
from status_list import StatusList
9+
10+
11+
def display_size(size_bytes):
12+
if size_bytes == 0:
13+
return "0B"
14+
size_name = ("B", "KB", "MB", "GB")
15+
floored = int(math.floor(math.log(size_bytes, 1024)))
16+
p = math.pow(1024, floored)
17+
rounded = round(size_bytes / p, 1)
18+
return "%s %s" % (rounded, size_name[floored])
19+
20+
21+
sizes = [100000, 1000000, 10000000, 100000000]
22+
rev_rates = [0.0001, 0.001, 0.01, 0.02, 0.05, 0.1, 0.25, 0.5, 0.75, 1]
23+
24+
data_sl = []
25+
data_uuid = []
26+
27+
for size in sizes:
28+
newdata_sl = {"size": size}
29+
newdata_uuid = {"size": size}
30+
for rev_rate in rev_rates:
31+
print(f"Revocation Rate: {rev_rate}")
32+
vals = [0, 1]
33+
p = [1 - rev_rate, rev_rate]
34+
sample = choices(population=vals, weights=p, k=size)
35+
36+
statuslist = StatusList(size, 1)
37+
idlist = bytearray()
38+
for idx, val in enumerate(sample):
39+
statuslist.set(idx, val)
40+
if val == 1:
41+
idlist.extend(uuid4().bytes)
42+
43+
rawsl = statuslist.encodeAsBytes()
44+
rawidlist = zlib.compress(idlist, level=9)
45+
46+
percentage = str(rev_rate * 100) + "%"
47+
newdata_sl[percentage] = display_size(len(rawsl))
48+
newdata_uuid[percentage] = display_size(len(rawidlist))
49+
print(f"Size in Bytes: {display_size(len(rawsl))}")
50+
print(f"Size in Bytes uuid: {display_size(len(rawidlist))}")
51+
data_sl.append(newdata_sl)
52+
data_uuid.append(newdata_uuid)
53+
54+
markdown_sl = (
55+
markdown_table(data_sl)
56+
.set_params(
57+
padding_width=3,
58+
padding_weight="centerleft",
59+
)
60+
.get_markdown()
61+
)
62+
print(markdown_sl)
63+
markdown_uuid = (
64+
markdown_table(data_uuid)
65+
.set_params(
66+
padding_width=3,
67+
padding_weight="centerleft",
68+
)
69+
.get_markdown()
70+
)
71+
print(markdown_uuid)

src/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ git+https://github.com/wbond/oscrypto.git@1547f535001ba568b239b8797465536759c742
44
jwcrypto==1.5.6
55
cbor2==5.6.2
66
cwt==2.7.4
7+
py_markdown_table==1.3.0

src/status_list.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import math
12
import zlib
23
from base64 import urlsafe_b64decode, urlsafe_b64encode
34
from typing import Dict
45

56
from cbor2 import dumps, loads
67

8+
LEVEL=9
79

810
class StatusList:
911
list: bytearray
@@ -13,7 +15,7 @@ class StatusList:
1315

1416
def __init__(self, size: int, bits: int):
1517
self.divisor = 8 // bits
16-
self.list = bytearray([0] * (size // self.divisor))
18+
self.list = bytearray([0] * math.ceil(size / self.divisor))
1719
self.bits = bits
1820
self.size = size
1921

@@ -24,11 +26,11 @@ def fromEncoded(cls, encoded: str, bits: int = 1):
2426
return new
2527

2628
def encodeAsString(self) -> str:
27-
zipped = zlib.compress(self.list, level=9)
29+
zipped = zlib.compress(self.list, level=LEVEL)
2830
return urlsafe_b64encode(zipped).decode().strip("=")
2931

3032
def encodeAsBytes(self) -> bytes:
31-
return zlib.compress(self.list, level=9)
33+
return zlib.compress(self.list, level=LEVEL)
3234

3335
def encodeAsJSON(self) -> Dict:
3436
encoded_list = self.encodeAsString()

0 commit comments

Comments
 (0)