Skip to content

Instantly share code, notes, and snippets.

@ryanrhymes
Last active January 19, 2018 20:59
Show Gist options
  • Save ryanrhymes/98b8262eaf9b851330976e2ab2f75bc2 to your computer and use it in GitHub Desktop.
Save ryanrhymes/98b8262eaf9b851330976e2ab2f75bc2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time
import math
import numpy as npy
m, n, o = 10, 1000, 10000
shape = [m,n,o]
def f00 () :
t0 = time.time()
x = npy.empty (shape)
t1 = time.time()
t = t1 - t0
print t
def f01 () :
t0 = time.time()
x = npy.zeros (shape)
t1 = time.time()
t = t1 - t0
print t
def f02 () :
t0 = time.time()
x = npy.ones (shape)
t1 = time.time()
t = t1 - t0
print t
def f03 () :
t0 = time.time()
x = npy.empty (shape)
x.fill (3.5)
t1 = time.time()
t = t1 - t0
print t
def f04 () :
x = npy.empty (shape)
x.fill (3.5)
y = npy.empty (shape)
y.fill (5.5)
t0 = time.time()
x + y
t1 = time.time()
t = t1 - t0
print t
def f05 () :
x = npy.empty (shape)
x.fill (3.5)
y = npy.empty (shape)
y.fill (5.5)
t0 = time.time()
x * y
t1 = time.time()
t = t1 - t0
print t
def f06 () :
x = npy.empty (shape)
x.fill (3.5)
t0 = time.time()
x + 2
t1 = time.time()
t = t1 - t0
print t
def f07 () :
x = npy.empty (shape)
x.fill (3.5)
t0 = time.time()
abs (x)
t1 = time.time()
t = t1 - t0
print t
def f08 () :
import math
x = npy.empty (shape)
x.fill (3.5)
y = npy.empty (shape)
t0 = time.time()
for i in range (m):
for j in range (n):
for k in range (o):
y[i,j,k] = (math.sin (x[i,j,k])) + 1
t1 = time.time()
t = t1 - t0
print t
def f09 () :
x = npy.empty (shape)
x.fill (3.5)
t0 = time.time()
for i in range (m):
for j in range (n):
for k in range (o):
x[i,j,k] > 0
t1 = time.time()
t = t1 - t0
print t
def f10 () :
x = npy.empty (shape)
x.fill (3.5)
y = npy.empty (shape)
y.fill (5.5)
t0 = time.time()
npy.less (x, y)
t1 = time.time()
t = t1 - t0
print t
def f95 () :
x = npy.empty (shape)
t0 = time.time()
for a in npy.nditer(x, op_flags=['readwrite']):
a[...] = (math.sin (a)) ** 2
t1 = time.time()
t = t1 - t0
print t
@ryanrhymes
Copy link
Author

ryanrhymes commented Jan 19, 2018

def f06 () :
  t0 = time.time()
  b = x[0:8:2,0:-1:2,-1:0:-1].copy()
  t1 = time.time()
  t = t1 - t0
  print t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment