Construct FunctionRaise

Performance Diagrams

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