import cPickle
import ipython1.kernel.api as kernel
import numpy as N
import time

print kernel.defaultController
rc = kernel.RemoteController(kernel.defaultController)
rc.block = True
print rc.getIDs()

#XXX rc.test()

x = N.arange(10000000)

### local benchmarks

t = time.clock()
dump = cPickle.dumps(x)
print 'cPickle dumps time', time.clock() - t

t = time.clock()
cPickle.loads(dump)
print 'cPickle loads time', time.clock() - t

t = time.clock()
z = map(lambda y: y*y, x)
print 'local map time', time.clock() - t

### go parallel

rc.executeAll('import time')

t = s = time.clock()
print 'pushing to all...'
rc.pushAll(x=x)
print 'total pushAll time', time.clock() - t

t = time.clock()
rc.executeAll('t = time.clock()')
print 'executing on all...'
rc.executeAll('z = map(lambda y:y*y, x)')
print 'executeAll time for map', time.clock() - t
rc.executeAll('t = time.clock() - t')

print 'total time for push and execute', time.clock() - s

rc.executeAll('print "engine map time", t')

for result in rc.getResultAll():
    print result
