Commit bb391d87 authored by Matthieu Boileau's avatar Matthieu Boileau

Simplify testmultiply.py

parent af683bab
from __future__ import print_function
import numpy as np
import timeit
import numexpr as ne
import timeit
N = 16384
N = 2**14
NUMBER = 5
a = np.random.rand(N, N)
def np_multiply():
return np.multiply(a, a)
def ne_multiply():
return ne.evaluate("a*a")
SETUP = "from __main__ import np, ne, a"
def run(funcname):
print("Testing {}()...".format(funcname))
s = "{}()".format(funcname)
setup = "from __main__ import {}".format(funcname)
t = timeit.timeit(s, setup=setup, number=NUMBER)
def run(s):
print("Testing {}...".format(s))
t = timeit.timeit(s, setup=SETUP, number=NUMBER)
print("time [s] = {0:.4f}".format(t/NUMBER))
if __name__ == '__main__':
print("Size n = {}".format(N))
run("np_multiply")
run("ne_multiply")
print("Allocating random Numpy array 'a' of size ({}, {})".format(N, N))
a = np.random.rand(N, N)
run("np.multiply(a, a)")
run("ne.evaluate('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