Mercurial > pylearn
comparison test_speed.py @ 277:6255359318bf
moved test_speed() in its own file
author | Frederic Bastien <bastienf@iro.umontreal.ca> |
---|---|
date | Thu, 05 Jun 2008 14:29:06 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
276:271a16d42072 | 277:6255359318bf |
---|---|
1 import numpy | |
2 from dataset import * | |
3 from misc import * | |
4 def test_speed(array, ds): | |
5 print "test_speed", ds.__class__ | |
6 | |
7 mat = numpy.random.rand(400,100) | |
8 | |
9 @print_timing | |
10 def f_array_full(a): | |
11 a+1 | |
12 @print_timing | |
13 def f_array_index(a): | |
14 for id in range(a.shape[0]): | |
15 # pass | |
16 a[id]+1 | |
17 # a[id]*mat | |
18 @print_timing | |
19 def f_array_iter(a): | |
20 for r in a: | |
21 # pass | |
22 r+1 | |
23 # r*mat | |
24 @print_timing | |
25 def f_ds_index(ds): | |
26 for id in range(len(ds)): | |
27 # pass | |
28 ds[id][0]+1 | |
29 # ds[id][0]*mat | |
30 @print_timing | |
31 def f_ds_iter(ds): | |
32 for ex in ds: | |
33 # pass | |
34 ex[0]+1 | |
35 # a[0]*mat | |
36 @print_timing | |
37 def f_ds_mb1(ds,mb_size): | |
38 for exs in ds.minibatches(minibatch_size = mb_size): | |
39 for ex in exs: | |
40 # pass | |
41 ex[0]+1 | |
42 # ex[0]*mat | |
43 @print_timing | |
44 def f_ds_mb2(ds,mb_size): | |
45 for exs in ds.minibatches(minibatch_size = mb_size): | |
46 # pass | |
47 exs[0]+1 | |
48 # ex[0]*mat | |
49 | |
50 f_array_full(array) | |
51 f_array_index(array) | |
52 f_array_iter(array) | |
53 | |
54 f_ds_index(ds) | |
55 f_ds_iter(ds) | |
56 | |
57 f_ds_mb1(ds,10) | |
58 f_ds_mb1(ds,100) | |
59 f_ds_mb1(ds,1000) | |
60 f_ds_mb1(ds,10000) | |
61 f_ds_mb2(ds,10) | |
62 f_ds_mb2(ds,100) | |
63 f_ds_mb2(ds,1000) | |
64 f_ds_mb2(ds,10000) | |
65 | |
66 if __name__=='__main__': | |
67 a2 = numpy.random.rand(100000,400) | |
68 ds1 = ArrayDataSet(a2,{'all':slice(0,a2.shape[1],1)}) | |
69 test_speed(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 test_speed(a2,ds4) | |
74 ds2=CachedDataSet(ds1,cache_all_upon_construction=False) | |
75 test_speed(a2,ds2) | |
76 ds3=CachedDataSet(ds1,cache_all_upon_construction=True) | |
77 test_speed(a2,ds3) | |
78 del a2,ds1,ds2,ds3 | |
79 |