##// END OF EJS Templates
Adding fix for %%time issue...
Pragnya Srinivasan -
Show More
@@ -1261,6 +1261,7 b' python-profiler package from non-free.""")'
1261 # Minimum time above which compilation time will be reported
1261 # Minimum time above which compilation time will be reported
1262 tc_min = 0.1
1262 tc_min = 0.1
1263
1263
1264 expr_val=None
1264 if len(expr_ast.body)==1 and isinstance(expr_ast.body[0], ast.Expr):
1265 if len(expr_ast.body)==1 and isinstance(expr_ast.body[0], ast.Expr):
1265 mode = 'eval'
1266 mode = 'eval'
1266 source = '<timed eval>'
1267 source = '<timed eval>'
@@ -1268,6 +1269,15 b' python-profiler package from non-free.""")'
1268 else:
1269 else:
1269 mode = 'exec'
1270 mode = 'exec'
1270 source = '<timed exec>'
1271 source = '<timed exec>'
1272 # multi-line %%time case
1273 if len(expr_ast.body) > 1 :
1274 expr_val=expr_ast.body[-1]
1275 code_val = self.shell.compile(ast.Expression(expr_val.value)
1276 , '<timed eval>'
1277 , 'eval')
1278 expr_ast=expr_ast.body[:-1]
1279 expr_ast = ast.Module(expr_ast)
1280
1271 t0 = clock()
1281 t0 = clock()
1272 code = self.shell.compile(expr_ast, source, mode)
1282 code = self.shell.compile(expr_ast, source, mode)
1273 tc = clock()-t0
1283 tc = clock()-t0
@@ -1289,11 +1299,15 b' python-profiler package from non-free.""")'
1289 st = clock2()
1299 st = clock2()
1290 try:
1300 try:
1291 exec(code, glob, local_ns)
1301 exec(code, glob, local_ns)
1302 out=None
1303 # multi-line %%time case
1304 if expr_val and isinstance(expr_val, ast.Expr):
1305 out = eval(code_val, glob, local_ns)
1292 except:
1306 except:
1293 self.shell.showtraceback()
1307 self.shell.showtraceback()
1294 return
1308 return
1295 end = clock2()
1309 end = clock2()
1296 out = None
1310
1297 wall_end = wtime()
1311 wall_end = wtime()
1298 # Compute actual times and report
1312 # Compute actual times and report
1299 wall_time = wall_end-wall_st
1313 wall_time = wall_end-wall_st
General Comments 0
You need to be logged in to leave comments. Login now