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

Method run

bench/bench.py:60–138  ·  view source on GitHub ↗

(self)

Source from the content-addressed store, hash-verified

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
92 timings['total_assemble'][I] = t1 - t0
93 timings['total'][I] = t2 - t0
94
95 if bool(self.compares):
96 for name, func in self.compares.items():
97 t3 = pc()
98 # func(*args)
99 func(x1, x2)
100 t4 = pc()
101 timings['compare', name][I] = t4 - t3
102
103 # Get Python times
104 for timingKey in nefunc.timings:
105 timings[timingKey][I] = nefunc.timings[timingKey]
106 # Get C times
107 if os.name == 'nt':
108 bench_times = ne3.interpreter.bench_times / ne3.interpreter.cpu_freq
109 else:
110 bench_times = ne3.interpreter.bench_times[0::2] + 1.0E-9*ne3.interpreter.bench_times[1::2]
111
112 timings['missing_assemble'][I] = timings['total_assemble'][I] - \
113 (timings['__init__'][I]+timings['frame_call'][I]+timings['ast_parse'][I]+timings['ast_walk'][I]+timings['to_tuple'][I]+timings['obj_construct'][I] )
114 timings['missing_run'][I] = timings['total_run'][I] - \
115 (np.sum(bench_times[0:10])+timings['run_pre'][I]+timings['run_post'][I])
116
117 for key,name in Case._C_BENCH.items():

Callers 1

bench.pyFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected