Package pylearn :: Package sandbox :: Module check_speed
[hide private]

Source Code for Module pylearn.sandbox.check_speed

 1  import numpy, time 
 2  from pylearn.datasets import * 
 3  #from misc import * 
 4  from pylearn.old_dataset.dataset import ArrayDataSet, CachedDataSet 
 5  from pylearn.old_dataset.lookup_list import LookupList 
12      return new_f 
13   
14 -def run(array, ds):
15 print "test_speed", ds.__class__ 16 17 mat = numpy.random.rand(400,100) 18 19 @print_timing 20 def f_array_full(a): 21 a+1
22 @print_timing 23 def f_array_index(a): 24 for id in range(a.shape[0]): 25 # pass 26 a[id]+1 27 # a[id]*mat 28 @print_timing 29 def f_array_iter(a): 30 for r in a: 31 # pass 32 r+1 33 # r*mat 34 @print_timing 35 def f_ds_index(ds): 36 for id in range(len(ds)): 37 # pass 38 ds[id][0]+1 39 # ds[id][0]*mat 40 @print_timing 41 def f_ds_iter(ds): 42 for ex in ds: 43 # pass 44 ex[0]+1 45 # a[0]*mat 46 @print_timing 47 def f_ds_mb1(ds,mb_size): 48 for exs in ds.minibatches(minibatch_size = mb_size): 49 for ex in exs: 50 # pass 51 ex[0]+1 52 # ex[0]*mat 53 54 f_array_full(array) 55 f_array_index(array) 56 f_array_iter(array) 57 58 f_ds_index(ds) 59 f_ds_iter(ds) 60 61 f_ds_mb1(ds,10) 62 f_ds_mb1(ds,100) 63 f_ds_mb1(ds,1000) 64 f_ds_mb1(ds,10000) 65
66 -def run_full():
67 a2 = numpy.random.rand(100000,400) 68 ds1 = ArrayDataSet(a2,{'all':slice(0,a2.shape[1],1)}) 69 run(a2, ds1) 70 a1 = numpy.random.rand(100000,40) 71 ds4 = ArrayDataSet(a1,LookupList(["f"+str(x)for x in range(a1.shape[1])], 72 range(a1.shape[1]))) 73 run(a2,ds4) 74 ds2=CachedDataSet(ds1,cache_all_upon_construction=False) 75 run(a2,ds2) 76 del ds2 77 ds3=CachedDataSet(ds1,cache_all_upon_construction=True) 78 run(a2,ds3) 79 del a2,ds1,ds3
80 81 if __name__=='__main__': 82 run_full() 83