Construct FunctionRaise

Performance Diagrams

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