Commit bb391d87 authored by Matthieu Boileau's avatar Matthieu Boileau


parent af683bab
from __future__ import print_function from __future__ import print_function
import numpy as np import numpy as np
import timeit
import numexpr as ne import numexpr as ne
import timeit
N = 16384 N = 2**14
a = np.random.rand(N, N) SETUP = "from __main__ import np, ne, a"
def np_multiply():
return np.multiply(a, a)
def ne_multiply():
return ne.evaluate("a*a")
def run(funcname): def run(s):
print("Testing {}()...".format(funcname)) print("Testing {}...".format(s))
s = "{}()".format(funcname) t = timeit.timeit(s, setup=SETUP, number=NUMBER)
setup = "from __main__ import {}".format(funcname)
t = timeit.timeit(s, setup=setup, number=NUMBER)
print("time [s] = {0:.4f}".format(t/NUMBER)) print("time [s] = {0:.4f}".format(t/NUMBER))
if __name__ == '__main__': if __name__ == '__main__':
print("Size n = {}".format(N)) print("Allocating random Numpy array 'a' of size ({}, {})".format(N, N))
run("np_multiply") a = np.random.rand(N, N)
run("ne_multiply") run("np.multiply(a, a)")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment