source: code/test_xordatastorespeedcomparison.py @ 23

Last change on this file since 23 was 23, checked in by trishank, 7 years ago

Add pre-release upPIR from June 2011.

File size: 2.0 KB
Line 
1# let's print out some speed benchmarks about the datastore types...
2
3# for timing...
4import time
5
6# for random bytes...
7import random
8
9# for ceil
10import math
11
12def random_bytes(size):
13 
14  # if it's huge, then repeat the same sequence every 64 biys
15  if size % 64 == 0:
16    return ("".join(chr(random.randrange(0, 256)) for i in xrange(64)))*(size/64)
17  return "".join(chr(random.randrange(0, 256)) for i in xrange(size))
18
19
20xordatastoremodules = ['fastsimplexordatastore', 'simplexordatastore']
21
22blocksizestotest = [1024, 1024*4, 1024*16, 1024*64, 1024*256, 1024*1024, 1024*1024*4, 1024*1024*16]
23numblockstotest = [16, 64, 256, 1024, 4*1024, 16*1024, 64*1024]
24
25
26max_size_to_test = 64*1024*1024
27
28ITERATIONS = 10
29
30# let's go through the modules separately...
31for modulename in xordatastoremodules:
32  # import the module
33  exec("import "+modulename)
34
35  for blocksize in blocksizestotest:
36    for numblocks in numblockstotest:
37
38      # Okay, let's do this datastore...
39
40      print modulename,"Blocksize:",blocksize,"blockcount:",numblocks,
41
42      # if it's too big, skip it
43      if blocksize*numblocks > max_size_to_test:
44        print "Skipped!"
45        continue
46
47
48      # create the datastore
49      thisxordatastore = eval(modulename+'.XORDatastore('+str(blocksize)+','+str(numblocks)+')')
50
51      # I used to just plop the data in, but building huge strings took forever
52      filledamount = 0
53      while filledamount < blocksize*numblocks:
54        amounttoadd = min(1024*64, blocksize*numblocks - filledamount)
55        # let's fill it with random data...
56        thisxordatastore.set_data(filledamount, random_bytes(amounttoadd))
57        filledamount += amounttoadd
58
59
60      bitstringlist = []
61      # let's generate the random bitstrings
62      for iteration in range(ITERATIONS):
63        # need to generate a long enough string...
64        bitstringlist.append(random_bytes(int(math.ceil(numblocks/8.0))))
65       
66
67      start = time.time()
68      for bitstring in bitstringlist:
69        thisxordatastore.produce_xor_from_bitstring(bitstring)
70      print (time.time() - start)/ITERATIONS
71
72
73
Note: See TracBrowser for help on using the repository browser.