MCPcopy Create free account
hub / github.com/pydata/numexpr / Case

Class Case

bench/bench.py:34–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 -6: Fore.LIGHTBLUE_EX, -7: Fore.BLUE, -8: Fore.MAGENTA }
33
34class Case(object):
35 _MAX_ARGS = 4
36 _C_BENCH = {0:'prepare_threads', 1:'run_preamble', 2:'magic_broadcast',
37 3:'npyiter_con', 4:'barrier_init', 5:'task_barrier_final',
38 6:'unlock_global', 7:'run_clean', 8:'release_gil',
39 9:'reacquire_gil',
40 50: 'cobj_init' }
41
42 _C_THREADS = {150:'thread_init', 200:'thread_tasks', 250:'thread_final'}
43
44 def initZeros(self):
45 # return [0.0]*self.tries
46 return np.zeros(self.tries, dtype='float64')
47
48 def __init__(self, expr, size, dtype, tries=1,
49 compares={}, nthreads=ne3.get_nthreads() ):
50 self.expr = expr
51 self.size = size
52 self.dtype = dtype
53 self.tries = tries
54 self.compares = compares # Should be a dict of {name: function_handle}
55 self.nthreads = nthreads
56 self.timings = defaultdict(self.initZeros, {})
57 self.stats = defaultdict(self.initZeros, {})
58
59
60 def run(self) -> None:
61 """
62 """
63 # Setup variables x1, x2, x3, x4
64 # print( "Running benchmark for '{}' x {} times".format(self.expr, self.tries))
65 args = []
66 varsDict = vars()
67 r = np.empty(self.size, dtype=self.dtype)
68 for I in range(Case._MAX_ARGS):
69 argName = 'x%d'%I
70
71 if argName in self.expr:
72 argArray = np.arange(self.size, dtype=self.dtype)
73 varsDict[argName] = argArray
74 args.append(argArray)
75
76 x1 = args[0]
77 x2 = args[1]
78 # Run benchmark `tries` times
79 ne3.set_nthreads(self.nthreads)
80 ne2.set_num_threads(self.nthreads)
81 # Numba does not have dynamic thread setting
82 for I in range(self.tries):
83 # Grab local references to our attributes
84 timings = self.timings; stats = self.stats
85
86 t0 = pc()
87 nefunc = ne3.NumExpr( self.expr )
88 t1 = pc()
89 nefunc()
90 t2 = pc()
91 timings['total_run'][I] = t2 - t1

Callers 1

bench.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…