this repo has no description
1import random
2from atmst import MemoryBlockStore, NodeStore, NodeWrangler
3from atmst.util import hash_to_cid
4import time
5
6dummy_cid = hash_to_cid(b"hello")
7
8def insert_random(n: int):
9 bs = MemoryBlockStore()
10 ns = NodeStore(bs)
11 nw = NodeWrangler(ns)
12 root = ns.get_node(None).cid
13 nw.put_record(root, "0", dummy_cid)
14 nw.put_record(root, "\xff", dummy_cid)
15 for _ in range(n):
16 root = nw.put_record(root, random.randbytes(8).hex(), dummy_cid)
17
18def insert_sequential(n: int):
19 bs = MemoryBlockStore()
20 ns = NodeStore(bs)
21 nw = NodeWrangler(ns)
22 root = ns.get_node(None).cid
23 nw.put_record(root, "0", dummy_cid)
24 nw.put_record(root, "\xff", dummy_cid)
25 for i in range(n):
26 root = nw.put_record(root, f"{i:08d}", dummy_cid)
27
28if __name__ == "__main__":
29 start = time.time()
30 insert_random(1000)
31 print("insert random", time.time() - start)
32
33 start = time.time()
34 insert_sequential(1000)
35 print("insert sequential", time.time() - start)