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