Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)48256325288.11538461538461257.0CPython 2.7174147903240.03846153846155414.9361405443759Nuitka (master)171697472391.96153846153845416.19097956605606Nuitka (develop)171697671543.8846153846154416.19087766032385Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)17682243188.11538461538461257.0CPython 3.5101293309240.03846153846155362.55452680487303Nuitka (master)101443504391.96153846153845362.34462416422724Nuitka (develop)101439556543.8846153846154362.3501416290248Nuitka (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_5f9db145d2589261a51a80d2856e2a5e; 94 static PyCodeObject *codeobj_5f9db145d2589261a51a80d2856e2a5e;
n 95 static PyCodeObject *codeobj_a54d7d7758456560daee102fadff4998; n 95 static PyCodeObject *codeobj_6ee75e5b1b11a512bf0af7d28b9d6d45;
96 static PyCodeObject *codeobj_61a1ad9e98d69ee27babbcac9d8c603b; 96 static PyCodeObject *codeobj_61a1ad9e98d69ee27babbcac9d8c603b;
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_9d136eee76212d03019efa5fd8964f6b; 102     module_filename_obj = const_str_digest_9d136eee76212d03019efa5fd8964f6b;
103     codeobj_5f9db145d2589261a51a80d2856e2a5e = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 103     codeobj_5f9db145d2589261a51a80d2856e2a5e = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
104     codeobj_main = codeobj_5f9db145d2589261a51a80d2856e2a5e; 104     codeobj_main = codeobj_5f9db145d2589261a51a80d2856e2a5e;
n 105     codeobj_a54d7d7758456560daee102fadff4998 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 105     codeobj_6ee75e5b1b11a512bf0af7d28b9d6d45 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
106     codeobj_61a1ad9e98d69ee27babbcac9d8c603b = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 106     codeobj_61a1ad9e98d69ee27babbcac9d8c603b = 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(  );
268 #ifndef __NUITKA_NO_ASSERT__ 268 #ifndef __NUITKA_NO_ASSERT__
269     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 269     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
270 #endif 270 #endif
271 271
272     // Local variable declarations. 272     // Local variable declarations.
n 273     struct Nuitka_FrameObject *frame_a54d7d7758456560daee102fadff4998; n
274     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
275     PyObject *exception_type = NULL;
276     PyObject *exception_value = NULL;
277     PyTracebackObject *exception_tb = NULL;
278     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
279     PyObject *exception_keeper_type_1;
280     PyObject *exception_keeper_value_1;
281     PyTracebackObject *exception_keeper_tb_1;
282     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
283     PyObject *exception_preserved_type_1;
284     PyObject *exception_preserved_value_1;
285     PyTracebackObject *exception_preserved_tb_1;
286     int tmp_res;
287     bool tmp_result;
288     PyObject *exception_keeper_type_2;
289     PyObject *exception_keeper_value_2;
290     PyTracebackObject *exception_keeper_tb_2;
291     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
292     static struct Nuitka_FrameObject *cache_frame_a54d7d7758456560daee102fadff4998 = NULL;
293     PyObject *tmp_return_value = NULL; 273     PyObject *tmp_return_value = NULL;
294 274
295     // Actual function code. 275     // Actual function code.
n 296     MAKE_OR_REUSE_FRAME( cache_frame_a54d7d7758456560daee102fadff4998, codeobj_a54d7d7758456560daee102fadff4998, module___main__, 0 ); n
297     frame_a54d7d7758456560daee102fadff4998 = cache_frame_a54d7d7758456560daee102fadff4998;
298  
299     // Push the new frame as the currently active one.
300     pushFrameStack( frame_a54d7d7758456560daee102fadff4998 );
301  
302     // Mark the frame object as in use, ref count 1 will be up for reuse.
303     assert( Py_REFCNT( frame_a54d7d7758456560daee102fadff4998 ) == 2 ); // Frame stack
304  
305     // Framed code:
306     {
307     // Tried code:
308     {
309     PyObject *tmp_called_name_1;
310     PyObject *tmp_mvar_value_1;
311     PyObject *tmp_call_result_1;
312     tmp_mvar_value_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
313  
314     if (unlikely( tmp_mvar_value_1 == NULL ))
315     {
316         tmp_mvar_value_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
317     }
318  
319     if ( tmp_mvar_value_1 == NULL )
320     {
321  
322         exception_type = PyExc_NameError;
323         Py_INCREF( exception_type );
324         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
325         exception_tb = NULL;
326         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
327         CHAIN_EXCEPTION( exception_value );
328  
329         exception_lineno = 34;
330  
331         goto try_except_handler_1;
332     }
333  
334     tmp_called_name_1 = tmp_mvar_value_1;
335     frame_a54d7d7758456560daee102fadff4998->m_frame.f_lineno = 34;
336     tmp_call_result_1 = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
337     if ( tmp_call_result_1 == NULL )
338     {
339         assert( ERROR_OCCURRED() );
340  
341         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
342  
343  
344         exception_lineno = 34;
345  
346         goto try_except_handler_1;
347     }
348     Py_DECREF( tmp_call_result_1 );
349     }
350     goto try_end_1;
351     // Exception handler code:
352     try_except_handler_1:;
353     exception_keeper_type_1 = exception_type;
354     exception_keeper_value_1 = exception_value;
355     exception_keeper_tb_1 = exception_tb;
356     exception_keeper_lineno_1 = exception_lineno;
357     exception_type = NULL;
358     exception_value = NULL;
359     exception_tb = NULL;
360     exception_lineno = 0;
361  
362     {
363     // Preserve existing published exception.
364     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
365     Py_XINCREF( exception_preserved_type_1 );
366     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
367     Py_XINCREF( exception_preserved_value_1 );
368     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
369     Py_XINCREF( exception_preserved_tb_1 );
370  
371     }
372     {
373     if ( exception_keeper_tb_1 == NULL )
374     {
375         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_a54d7d7758456560daee102fadff4998, exception_keeper_lineno_1 );
376     }
377     else if ( exception_keeper_lineno_1 != 0 )
378     {
379         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_a54d7d7758456560daee102fadff4998, exception_keeper_lineno_1 );
380     }
381  
382     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
383     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
384     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
385     }
386     {
387     // Tried code:
388     {
389     nuitka_bool tmp_condition_result_1;
390     PyObject *tmp_operand_name_1;
391     PyObject *tmp_compexpr_left_1;
392     PyObject *tmp_compexpr_right_1;
393     tmp_compexpr_left_1 = EXC_TYPE(PyThreadState_GET());
394     tmp_compexpr_right_1 = PyExc_TypeError;
395     tmp_res = EXCEPTION_MATCH_BOOL( tmp_compexpr_left_1, tmp_compexpr_right_1 );
396     if ( tmp_res == -1 )
397     {
398         assert( ERROR_OCCURRED() );
399  
400         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
401  
402  
403         exception_lineno = 35;
404  
405         goto try_except_handler_2;
406     }
407     tmp_operand_name_1 = ( tmp_res != 0 ) ? Py_True : Py_False;
408     tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
409     if ( tmp_res == -1 )
410     {
411         assert( ERROR_OCCURRED() );
412  
413         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
414  
415  
416         exception_lineno = 35;
417  
418         goto try_except_handler_2;
419     }
420     tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
421     if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
422     {
423         goto branch_yes_1;
424     }
425     else
426     {
427         goto branch_no_1;
428     }
429     branch_yes_1:;
430     {
431     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
432     if (unlikely( tmp_result == false ))
433     {
434         exception_lineno = 33;
435     }
436  
437     if (exception_tb && exception_tb->tb_frame == &frame_a54d7d7758456560daee102fadff4998->m_frame) frame_a54d7d7758456560daee102fadff4998->m_frame.f_lineno = exception_tb->tb_lineno;
438  
439     goto try_except_handler_2;
440     }
441     branch_no_1:;
442     }
443     goto try_end_2;
444     // Exception handler code:
445     try_except_handler_2:;
446     exception_keeper_type_2 = exception_type;
447     exception_keeper_value_2 = exception_value;
448     exception_keeper_tb_2 = exception_tb;
449     exception_keeper_lineno_2 = exception_lineno;
450     exception_type = NULL;
451     exception_value = NULL;
452     exception_tb = NULL;
453     exception_lineno = 0;
454  
455     {
456     // Restore previous exception.
457     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
458     }
459     {
460     // Re-raise.
461     exception_type = exception_keeper_type_2;
462     exception_value = exception_keeper_value_2;
463     exception_tb = exception_keeper_tb_2;
464     exception_lineno = exception_keeper_lineno_2;
465  
466     goto frame_exception_exit_1;
467     }
468     // End of try:
469     try_end_2:;
470     }
471     {
472     // Restore previous exception.
473     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
474     }
475     goto try_end_1;
476     // exception handler codes exits in all cases
477     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
478     return NULL;
479     // End of try:
480     try_end_1:;
481     }
482  
483 #if 0
484     RESTORE_FRAME_EXCEPTION( frame_a54d7d7758456560daee102fadff4998 );
485 #endif
486  
487     // Put the previous frame back on top.
488     popFrameStack();
489  
490     goto frame_no_exception_1;
491  
492     frame_exception_exit_1:;
493  
494 #if 0
495     RESTORE_FRAME_EXCEPTION( frame_a54d7d7758456560daee102fadff4998 );
496 #endif
497  
498     if ( exception_tb == NULL )
499     {
500         exception_tb = MAKE_TRACEBACK( frame_a54d7d7758456560daee102fadff4998, exception_lineno );
501     }
502     else if ( exception_tb->tb_frame != &frame_a54d7d7758456560daee102fadff4998->m_frame )
503     {
504         exception_tb = ADD_TRACEBACK( exception_tb, frame_a54d7d7758456560daee102fadff4998, exception_lineno );
505     }
506  
507     // Attachs locals to frame if any.
508     Nuitka_Frame_AttachLocals(
509         (struct Nuitka_FrameObject *)frame_a54d7d7758456560daee102fadff4998,
510         type_description_1
511     );
512  
513  
514     // Release cached frame.
515     if ( frame_a54d7d7758456560daee102fadff4998 == cache_frame_a54d7d7758456560daee102fadff4998 )
516     {
517         Py_DECREF( frame_a54d7d7758456560daee102fadff4998 );
518     }
519     cache_frame_a54d7d7758456560daee102fadff4998 = NULL;
520  
521     assertFrameObject( frame_a54d7d7758456560daee102fadff4998 );
522  
523     // Put the previous frame back on top.
524     popFrameStack();
525  
526     // Return the error.
527     goto function_exception_exit;
528  
529     frame_no_exception_1:;
530     { 276     {
531     tmp_return_value = Py_None; 277     tmp_return_value = Py_None;
532     Py_INCREF( tmp_return_value ); 278     Py_INCREF( tmp_return_value );
533     goto function_return_exit; 279     goto function_return_exit;
534     } 280     }
535 281
536     // Return statement must have exited already. 282     // Return statement must have exited already.
537     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 283     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
538     return NULL; 284     return NULL;
539 285
n 540 function_exception_exit: n
541     assert( exception_type );
542     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
543  
544     return NULL;
545 function_return_exit: 286 function_return_exit:
546 287
547 CHECK_OBJECT( tmp_return_value ); 288 CHECK_OBJECT( tmp_return_value );
548 assert( had_error || !ERROR_OCCURRED() ); 289 assert( had_error || !ERROR_OCCURRED() );
549 return tmp_return_value; 290 return tmp_return_value;
582         impl___main__$$$function_2_calledRepeatedly, 323         impl___main__$$$function_2_calledRepeatedly,
583         const_str_plain_calledRepeatedly, 324         const_str_plain_calledRepeatedly,
584 #if PYTHON_VERSION >= 300 325 #if PYTHON_VERSION >= 300
585         NULL, 326         NULL,
586 #endif 327 #endif
n 587         codeobj_a54d7d7758456560daee102fadff4998, n 328         codeobj_6ee75e5b1b11a512bf0af7d28b9d6d45,
588         NULL, 329         NULL,
589 #if PYTHON_VERSION >= 300 330 #if PYTHON_VERSION >= 300
590         NULL, 331         NULL,
591         NULL, 332         NULL,
592 #endif 333 #endif
1154         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 895         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
1155         exception_tb = NULL; 896         exception_tb = NULL;
1156         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 897         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
1157         CHAIN_EXCEPTION( exception_value ); 898         CHAIN_EXCEPTION( exception_value );
1158 899
n 1159         exception_lineno = 46; n 900         exception_lineno = 48;
1160 901
1161         goto frame_exception_exit_1; 902         goto frame_exception_exit_1;
1162     } 903     }
1163 904
1164     tmp_compexpr_left_1 = tmp_mvar_value_3; 905     tmp_compexpr_left_1 = tmp_mvar_value_3;
n 1165     tmp_compexpr_right_1 = const_int_pos_50000; n 906     tmp_compexpr_right_1 = const_int_0;
1166     tmp_operand_name_1 = RICH_COMPARE_EQ_OBJECT_OBJECT_NORECURSE( tmp_compexpr_left_1, tmp_compexpr_right_1 ); 907     tmp_operand_name_1 = RICH_COMPARE_EQ_OBJECT_OBJECT_NORECURSE( tmp_compexpr_left_1, tmp_compexpr_right_1 );
1167     if ( tmp_operand_name_1 == NULL ) 908     if ( tmp_operand_name_1 == NULL )
1168     { 909     {
1169         assert( ERROR_OCCURRED() ); 910         assert( ERROR_OCCURRED() );
1170 911
1171         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 912         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1172 913
1173 914
n 1174         exception_lineno = 46; n 915         exception_lineno = 48;
1175 916
1176         goto frame_exception_exit_1; 917         goto frame_exception_exit_1;
1177     } 918     }
1178     tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 ); 919     tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
1179     Py_DECREF( tmp_operand_name_1 ); 920     Py_DECREF( tmp_operand_name_1 );
1182         assert( ERROR_OCCURRED() ); 923         assert( ERROR_OCCURRED() );
1183 924
1184         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 925         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1185 926
1186 927
n 1187         exception_lineno = 46; n 928         exception_lineno = 48;
1188 929
1189         goto frame_exception_exit_1; 930         goto frame_exception_exit_1;
1190     } 931     }
1191     tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE; 932     tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1192     if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE ) 933     if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
1201     { 942     {
1202     PyObject *tmp_raise_type_1; 943     PyObject *tmp_raise_type_1;
1203     tmp_raise_type_1 = PyExc_AssertionError; 944     tmp_raise_type_1 = PyExc_AssertionError;
1204     exception_type = tmp_raise_type_1; 945     exception_type = tmp_raise_type_1;
1205     Py_INCREF( tmp_raise_type_1 ); 946     Py_INCREF( tmp_raise_type_1 );
t 1206     exception_lineno = 46; t 947     exception_lineno = 48;
1207     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 948     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
1208 949
1209     goto frame_exception_exit_1; 950     goto frame_exception_exit_1;
1210     } 951     }
1211     branch_no_1:; 952     branch_no_1:;