Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)48256325288.11538461538461257.0CPython 2.7173395974240.03846153846155415.3211951942448Nuitka (master)173396786391.96153846153845415.32077937789023Nuitka (develop)173396882543.8846153846154415.32073021733595Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)17682243188.11538461538461257.0CPython 3.5100488968240.03846153846155363.6786208151908Nuitka (master)100491718391.96153846153845363.67477759629685Nuitka (develop)100488772543.8846153846154363.67889473188285Nuitka (factory)Construct FunctionRaiseTicks

Source Code with Construct

from __future__ import print_function

count = 0

def raisy():
    global count
    count += 1

    raise TypeError

def calledRepeatedly():
# construct_begin
    try:
        raisy()
    except TypeError:
        pass
# construct_alternative



import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

# construct_begin
assert count == 50000
# construct_alternative


print("OK.")

Source Code without Construct

from __future__ import print_function

count = 0

def raisy():
    global count
    count += 1

    raise TypeError

def calledRepeatedly():
# construct_begin




# construct_alternative
    pass
# construct_end

import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

# construct_begin

# construct_alternative
assert count == 0
# construct_end
print("OK.")

Context Diff of Source Code


Construct
Baseline
28 28
29     raise TypeError 29     raise TypeError
30 30
31 def calledRepeatedly(): 31 def calledRepeatedly():
32 # construct_begin 32 # construct_begin
n 33     try: n
34         raisy()
35     except TypeError:
36         pass
37 # construct_alternative
38 33
39 34
n n 35  
36  
37 # construct_alternative
38     pass
39 # construct_end
40 40
41 import itertools 41 import itertools
42 for x in itertools.repeat(None, 50000): 42 for x in itertools.repeat(None, 50000):
43     calledRepeatedly() 43     calledRepeatedly()
44 44
45 # construct_begin 45 # construct_begin
n 46 assert count == 50000 n 46  
47 # construct_alternative 47 # construct_alternative
t 48   t 48 assert count == 0
49   49 # construct_end
50 print("OK.") 50 print("OK.")
51 51

Context Diff of Generated Code


Construct
Baseline
90 } 90 }
91 #endif 91 #endif
92 92
93 // The module code objects. 93 // The module code objects.
94 static PyCodeObject *codeobj_cbbbe8986b42333b18009d629eabf8d9; 94 static PyCodeObject *codeobj_cbbbe8986b42333b18009d629eabf8d9;
n 95 static PyCodeObject *codeobj_9985b6792c88abd0ea809730aca7ab01; n 95 static PyCodeObject *codeobj_597c47c6a923292b7106b5b86c7ceae1;
96 static PyCodeObject *codeobj_2dac17df49880a763a6721a037fb8ffb; 96 static PyCodeObject *codeobj_2dac17df49880a763a6721a037fb8ffb;
97 /* For use in "MainProgram.c". */ 97 /* For use in "MainProgram.c". */
98 PyCodeObject *codeobj_main = NULL; 98 PyCodeObject *codeobj_main = NULL;
99 99
100 static void createModuleCodeObjects(void) 100 static void createModuleCodeObjects(void)
101 { 101 {
102     module_filename_obj = const_str_digest_0f9f5ad0c35ccf6d2286828c6af5de2b; 102     module_filename_obj = const_str_digest_0f9f5ad0c35ccf6d2286828c6af5de2b;
103     codeobj_cbbbe8986b42333b18009d629eabf8d9 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 103     codeobj_cbbbe8986b42333b18009d629eabf8d9 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
104     codeobj_main = codeobj_cbbbe8986b42333b18009d629eabf8d9; 104     codeobj_main = codeobj_cbbbe8986b42333b18009d629eabf8d9;
n 105     codeobj_9985b6792c88abd0ea809730aca7ab01 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 105     codeobj_597c47c6a923292b7106b5b86c7ceae1 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
106     codeobj_2dac17df49880a763a6721a037fb8ffb = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 106     codeobj_2dac17df49880a763a6721a037fb8ffb = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE );
107 } 107 }
108 108
109 // The module function declarations. 109 // The module function declarations.
110 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  ); 110 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  );
261 #ifndef __NUITKA_NO_ASSERT__ 261 #ifndef __NUITKA_NO_ASSERT__
262     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 262     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
263 #endif 263 #endif
264 264
265     // Local variable declarations. 265     // Local variable declarations.
n 266     struct Nuitka_FrameObject *frame_9985b6792c88abd0ea809730aca7ab01; n
267     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
268     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused;
269     PyObject *exception_type = NULL;
270     PyObject *exception_value = NULL;
271     PyTracebackObject *exception_tb = NULL;
272     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
273     PyObject *exception_keeper_type_1;
274     PyObject *exception_keeper_value_1;
275     PyTracebackObject *exception_keeper_tb_1;
276     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
277     PyObject *exception_preserved_type_1;
278     PyObject *exception_preserved_value_1;
279     PyTracebackObject *exception_preserved_tb_1;
280     bool tmp_result;
281     PyObject *exception_keeper_type_2;
282     PyObject *exception_keeper_value_2;
283     PyTracebackObject *exception_keeper_tb_2;
284     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
285     static struct Nuitka_FrameObject *cache_frame_9985b6792c88abd0ea809730aca7ab01 = NULL;
286     PyObject *tmp_return_value = NULL; 266     PyObject *tmp_return_value = NULL;
287 267
288     // Actual function code. 268     // Actual function code.
n 289     MAKE_OR_REUSE_FRAME( cache_frame_9985b6792c88abd0ea809730aca7ab01, codeobj_9985b6792c88abd0ea809730aca7ab01, module___main__, 0 ); n
290     frame_9985b6792c88abd0ea809730aca7ab01 = cache_frame_9985b6792c88abd0ea809730aca7ab01;
291  
292     // Push the new frame as the currently active one.
293     pushFrameStack( frame_9985b6792c88abd0ea809730aca7ab01 );
294  
295     // Mark the frame object as in use, ref count 1 will be up for reuse.
296     assert( Py_REFCNT( frame_9985b6792c88abd0ea809730aca7ab01 ) == 2 ); // Frame stack
297  
298     // Framed code:
299     {
300     // Tried code:
301     {
302     PyObject *tmp_called_name_1;
303     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
304  
305     if (unlikely( tmp_called_name_1 == NULL ))
306     {
307         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
308     }
309  
310     if ( tmp_called_name_1 == NULL )
311     {
312  
313         exception_type = PyExc_NameError;
314         Py_INCREF( exception_type );
315         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
316         exception_tb = NULL;
317         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
318         CHAIN_EXCEPTION( exception_value );
319  
320         exception_lineno = 34;
321  
322         goto try_except_handler_1;
323     }
324  
325     frame_9985b6792c88abd0ea809730aca7ab01->m_frame.f_lineno = 34;
326     tmp_unused = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
327     if ( tmp_unused == NULL )
328     {
329         assert( ERROR_OCCURRED() );
330  
331         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
332  
333  
334         exception_lineno = 34;
335  
336         goto try_except_handler_1;
337     }
338     Py_DECREF( tmp_unused );
339     }
340     goto try_end_1;
341     // Exception handler code:
342     try_except_handler_1:;
343     exception_keeper_type_1 = exception_type;
344     exception_keeper_value_1 = exception_value;
345     exception_keeper_tb_1 = exception_tb;
346     exception_keeper_lineno_1 = exception_lineno;
347     exception_type = NULL;
348     exception_value = NULL;
349     exception_tb = NULL;
350     exception_lineno = 0;
351  
352     {
353     // Preserve existing published exception.
354     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
355     Py_XINCREF( exception_preserved_type_1 );
356     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
357     Py_XINCREF( exception_preserved_value_1 );
358     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
359     Py_XINCREF( exception_preserved_tb_1 );
360  
361     }
362     {
363     if ( exception_keeper_tb_1 == NULL )
364     {
365         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_9985b6792c88abd0ea809730aca7ab01, exception_keeper_lineno_1 );
366     }
367     else if ( exception_keeper_lineno_1 != 0 )
368     {
369         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_9985b6792c88abd0ea809730aca7ab01, exception_keeper_lineno_1 );
370     }
371  
372     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
373     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
374     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
375     }
376     {
377     // Tried code:
378     {
379     PyObject *tmp_compare_left_1;
380     PyObject *tmp_compare_right_1;
381     int tmp_exc_match_exception_match_1;
382     tmp_compare_left_1 = EXC_TYPE(PyThreadState_GET());
383     tmp_compare_right_1 = PyExc_TypeError;
384     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
385     if ( tmp_exc_match_exception_match_1 == -1 )
386     {
387         assert( ERROR_OCCURRED() );
388  
389         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
390  
391  
392         exception_lineno = 35;
393  
394         goto try_except_handler_2;
395     }
396     if ( tmp_exc_match_exception_match_1 == 1 )
397     {
398         goto branch_no_1;
399     }
400     else
401     {
402         goto branch_yes_1;
403     }
404     branch_yes_1:;
405     {
406     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
407     if (unlikely( tmp_result == false ))
408     {
409         exception_lineno = 33;
410     }
411  
412     if (exception_tb && exception_tb->tb_frame == &frame_9985b6792c88abd0ea809730aca7ab01->m_frame) frame_9985b6792c88abd0ea809730aca7ab01->m_frame.f_lineno = exception_tb->tb_lineno;
413  
414     goto try_except_handler_2;
415     }
416     branch_no_1:;
417     }
418     goto try_end_2;
419     // Exception handler code:
420     try_except_handler_2:;
421     exception_keeper_type_2 = exception_type;
422     exception_keeper_value_2 = exception_value;
423     exception_keeper_tb_2 = exception_tb;
424     exception_keeper_lineno_2 = exception_lineno;
425     exception_type = NULL;
426     exception_value = NULL;
427     exception_tb = NULL;
428     exception_lineno = 0;
429  
430     {
431     // Restore previous exception.
432     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
433     }
434     {
435     // Re-raise.
436     exception_type = exception_keeper_type_2;
437     exception_value = exception_keeper_value_2;
438     exception_tb = exception_keeper_tb_2;
439     exception_lineno = exception_keeper_lineno_2;
440  
441     goto frame_exception_exit_1;
442     }
443     // End of try:
444     try_end_2:;
445     }
446     {
447     // Restore previous exception.
448     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
449     }
450     goto try_end_1;
451     // exception handler codes exits in all cases
452     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
453     return NULL;
454     // End of try:
455     try_end_1:;
456     }
457  
458 #if 0
459     RESTORE_FRAME_EXCEPTION( frame_9985b6792c88abd0ea809730aca7ab01 );
460 #endif
461  
462     // Put the previous frame back on top.
463     popFrameStack();
464  
465     goto frame_no_exception_1;
466  
467     frame_exception_exit_1:;
468  
469 #if 0
470     RESTORE_FRAME_EXCEPTION( frame_9985b6792c88abd0ea809730aca7ab01 );
471 #endif
472  
473     if ( exception_tb == NULL )
474     {
475         exception_tb = MAKE_TRACEBACK( frame_9985b6792c88abd0ea809730aca7ab01, exception_lineno );
476     }
477     else if ( exception_tb->tb_frame != &frame_9985b6792c88abd0ea809730aca7ab01->m_frame )
478     {
479         exception_tb = ADD_TRACEBACK( exception_tb, frame_9985b6792c88abd0ea809730aca7ab01, exception_lineno );
480     }
481  
482     // Attachs locals to frame if any.
483     Nuitka_Frame_AttachLocals(
484         (struct Nuitka_FrameObject *)frame_9985b6792c88abd0ea809730aca7ab01,
485         type_description_1
486     );
487  
488  
489     // Release cached frame.
490     if ( frame_9985b6792c88abd0ea809730aca7ab01 == cache_frame_9985b6792c88abd0ea809730aca7ab01 )
491     {
492         Py_DECREF( frame_9985b6792c88abd0ea809730aca7ab01 );
493     }
494     cache_frame_9985b6792c88abd0ea809730aca7ab01 = NULL;
495  
496     assertFrameObject( frame_9985b6792c88abd0ea809730aca7ab01 );
497  
498     // Put the previous frame back on top.
499     popFrameStack();
500  
501     // Return the error.
502     goto function_exception_exit;
503  
504     frame_no_exception_1:;
505  
506     { 269     {
507     tmp_return_value = Py_None; 270     tmp_return_value = Py_None;
508     Py_INCREF( tmp_return_value ); 271     Py_INCREF( tmp_return_value );
509     goto function_return_exit; 272     goto function_return_exit;
510     } 273     }
511 274
512     // Return statement must have exited already. 275     // Return statement must have exited already.
513     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 276     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
514     return NULL; 277     return NULL;
515 278
n 516 function_exception_exit: n
517     assert( exception_type );
518     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
519  
520     return NULL;
521 function_return_exit: 279 function_return_exit:
522 280
523 CHECK_OBJECT( tmp_return_value ); 281 CHECK_OBJECT( tmp_return_value );
524 assert( had_error || !ERROR_OCCURRED() ); 282 assert( had_error || !ERROR_OCCURRED() );
525 return tmp_return_value; 283 return tmp_return_value;
558         impl___main__$$$function_2_calledRepeatedly, 316         impl___main__$$$function_2_calledRepeatedly,
559         const_str_plain_calledRepeatedly, 317         const_str_plain_calledRepeatedly,
560 #if PYTHON_VERSION >= 300 318 #if PYTHON_VERSION >= 300
561         NULL, 319         NULL,
562 #endif 320 #endif
n 563         codeobj_9985b6792c88abd0ea809730aca7ab01, n 321         codeobj_597c47c6a923292b7106b5b86c7ceae1,
564         NULL, 322         NULL,
565 #if PYTHON_VERSION >= 300 323 #if PYTHON_VERSION >= 300
566         NULL, 324         NULL,
567         NULL, 325         NULL,
568 #endif 326 #endif
1193         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 951         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
1194         exception_tb = NULL; 952         exception_tb = NULL;
1195         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 953         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
1196         CHAIN_EXCEPTION( exception_value ); 954         CHAIN_EXCEPTION( exception_value );
1197 955
n 1198         exception_lineno = 46; n 956         exception_lineno = 48;
1199 957
1200         goto frame_exception_exit_1; 958         goto frame_exception_exit_1;
1201     } 959     }
1202 960
n 1203     tmp_compare_right_2 = const_int_pos_50000; n 961     tmp_compare_right_2 = const_int_0;
1204     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_2, tmp_compare_right_2 ); 962     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_2, tmp_compare_right_2 );
1205     if ( tmp_cmp_Eq_1 == -1 ) 963     if ( tmp_cmp_Eq_1 == -1 )
1206     { 964     {
1207         assert( ERROR_OCCURRED() ); 965         assert( ERROR_OCCURRED() );
1208 966
1209         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 967         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1210 968
1211 969
n 1212         exception_lineno = 46; n 970         exception_lineno = 48;
1213 971
1214         goto frame_exception_exit_1; 972         goto frame_exception_exit_1;
1215     } 973     }
1216     if ( tmp_cmp_Eq_1 == 1 ) 974     if ( tmp_cmp_Eq_1 == 1 )
1217     { 975     {
1225     { 983     {
1226     PyObject *tmp_raise_type_1; 984     PyObject *tmp_raise_type_1;
1227     tmp_raise_type_1 = PyExc_AssertionError; 985     tmp_raise_type_1 = PyExc_AssertionError;
1228     exception_type = tmp_raise_type_1; 986     exception_type = tmp_raise_type_1;
1229     Py_INCREF( tmp_raise_type_1 ); 987     Py_INCREF( tmp_raise_type_1 );
t 1230     exception_lineno = 46; t 988     exception_lineno = 48;
1231     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 989     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
1232 990
1233     goto frame_exception_exit_1; 991     goto frame_exception_exit_1;
1234     } 992     }
1235     branch_no_2:; 993     branch_no_2:;