2 # This example measures the performance of Path ORAM
3 # when storage is accessed through a local file.
11 from pyoram.util.misc import MemorySize
12 from pyoram.oblivious_storage.tree.path_oram import \
17 pyoram.config.SHOW_PROGRESS_BAR = True
19 # Set the storage location and size
20 storage_name = "heap.bin"
23 # one block per bucket in the
24 # storage heap of height 8
25 block_count = 2**(8+1)-1
29 print("Storage Name: %s" % (storage_name))
30 print("Block Count: %s" % (block_count))
31 print("Block Size: %s" % (MemorySize(block_size)))
32 print("Total Memory: %s"
33 % (MemorySize(block_size*block_count)))
34 print("Actual Storage Required: %s"
36 PathORAM.compute_storage_size(
39 storage_type='file'))))
42 print("Setting Up Path ORAM Storage")
43 setup_start = time.time()
44 with PathORAM.setup(storage_name,
48 ignore_existing=True) as f:
49 print("Total Setup Time: %2.f s"
50 % (time.time()-setup_start))
51 print("Current Stash Size: %s"
53 print("Total Data Transmission: %s"
54 % (MemorySize(f.bytes_sent + f.bytes_received)))
57 # We close the device and reopen it after
58 # setup to reset the bytes sent and bytes
60 with PathORAM(storage_name,
64 storage_type='file') as f:
67 start_time = time.time()
68 for t in tqdm.tqdm(list(range(test_count)),
69 desc="Running I/O Performance Test"):
70 f.read_block(random.randint(0,f.block_count-1))
71 stop_time = time.time()
72 print("Current Stash Size: %s"
74 print("Access Block Avg. Data Transmitted: %s (%.3fx)"
75 % (MemorySize((f.bytes_sent + f.bytes_received)/float(test_count)),
76 (f.bytes_sent + f.bytes_received)/float(test_count)/float(block_size)))
77 print("Access Block Avg. Latency: %.2f ms"
78 % ((stop_time-start_time)/float(test_count)*1000))
81 # cleanup because this is a test example
82 os.remove(storage_name)
84 if __name__ == "__main__":
85 main() # pragma: no cover