view test_speed.py @ 324:ce79bf5fa463

- the cut and paste between file and dir conditions is always a bad thing - i made one function (hg_version) to basically call and parse hg - i made a function to include the cases of what might be returned by imp.find_modules (_input_id) - the check for a .hg folder was insufficient. Lots of things could go wrong. Instead I use the return code from the Popen process. The return code catches this and any other problem that hg runs into. - its easier to offer more rcs support in future (cvs,svn,git)
author James Bergstra <bergstrj@iro.umontreal.ca>
date Thu, 12 Jun 2008 20:54:49 -0400
parents 6255359318bf
children
line wrap: on
line source

import numpy
from dataset import *
from misc import *
def test_speed(array, ds):
    print "test_speed", ds.__class__

    mat = numpy.random.rand(400,100)

    @print_timing
    def f_array_full(a):
        a+1
    @print_timing
    def f_array_index(a):
        for id in range(a.shape[0]):
#            pass
            a[id]+1
#            a[id]*mat
    @print_timing
    def f_array_iter(a):
        for r in a:
#            pass
            r+1
#            r*mat
    @print_timing
    def f_ds_index(ds):
        for id in range(len(ds)):
#            pass
            ds[id][0]+1
#            ds[id][0]*mat
    @print_timing
    def f_ds_iter(ds):
        for ex in ds:
#            pass
            ex[0]+1
#            a[0]*mat
    @print_timing
    def f_ds_mb1(ds,mb_size):
        for exs in ds.minibatches(minibatch_size = mb_size):
            for ex in exs:
#                pass
                ex[0]+1
#                ex[0]*mat
    @print_timing
    def f_ds_mb2(ds,mb_size):
        for exs in ds.minibatches(minibatch_size = mb_size):
#            pass
            exs[0]+1
#            ex[0]*mat

    f_array_full(array)
    f_array_index(array)
    f_array_iter(array)

    f_ds_index(ds)
    f_ds_iter(ds)

    f_ds_mb1(ds,10)
    f_ds_mb1(ds,100)
    f_ds_mb1(ds,1000)
    f_ds_mb1(ds,10000)
    f_ds_mb2(ds,10)
    f_ds_mb2(ds,100)
    f_ds_mb2(ds,1000)
    f_ds_mb2(ds,10000)

if __name__=='__main__':
    a2 = numpy.random.rand(100000,400)
    ds1 = ArrayDataSet(a2,{'all':slice(0,a2.shape[1],1)})
    test_speed(a2,ds1)
    a1 = numpy.random.rand(100000,40)
    ds4 = ArrayDataSet(a1,LookupList(["f"+str(x)for x in range(a1.shape[1])],
                                     range(a1.shape[1])))
    test_speed(a2,ds4)
    ds2=CachedDataSet(ds1,cache_all_upon_construction=False)
    test_speed(a2,ds2)
    ds3=CachedDataSet(ds1,cache_all_upon_construction=True)
    test_speed(a2,ds3)
    del a2,ds1,ds2,ds3