#!/usr/bin/env python #------------- # Load modules #------------- import time from numpy import * a = linspace(0, 1, 1E+08) # create some array t0 = time.clock() b = 3*a - 1 t1 = time.clock() # t1-t0 is the CPU time of 3*a-1 for i in xrange(a.size): b[i] = 3*a[i] - 1 t2 = time.clock() b = a b *= 3 b -= 1 t3 = time.clock() print 'Computing b= 3*a-1', a.size print ' Vec: %15.10f sec' % (t1-t0) print ' Loop: %15.10f sec' % (t2-t1) print 'In-Place: %15.10f sec' % (t3-t2)