Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)48076588088.11538461538461257.0CPython 2.7171697241240.03846153846155415.862387653297Nuitka (master)171697253391.96153846153845415.86238148525405Nuitka (develop)171698117543.8846153846154415.86193738615884Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)17812194788.11538461538461257.0CPython 3.5101442824240.03846153846155363.3798778940777Nuitka (master)101442505391.96153846153845363.3803204549694Nuitka (develop)101437441543.8846153846154363.3873459357076Nuitka (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_0a96bfb0b3bb72ca71e8fbf1e1cbbeae; 97 static PyCodeObject *codeobj_0a96bfb0b3bb72ca71e8fbf1e1cbbeae;
n 98 static PyCodeObject *codeobj_a3cd2cb40582c9dff826eafbf16b9e5f; n 98 static PyCodeObject *codeobj_c035c0b708260fb973901a52c1a8698d;
99 static PyCodeObject *codeobj_fb65d31aaa3bbc288654f128bbb28377; 99 static PyCodeObject *codeobj_fb65d31aaa3bbc288654f128bbb28377;
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_0fcae5fb09dd95859333775616ca1ca2; 105     module_filename_obj = const_str_digest_0fcae5fb09dd95859333775616ca1ca2;
106     codeobj_0a96bfb0b3bb72ca71e8fbf1e1cbbeae = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 106     codeobj_0a96bfb0b3bb72ca71e8fbf1e1cbbeae = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
107     codeobj_main = codeobj_0a96bfb0b3bb72ca71e8fbf1e1cbbeae; 107     codeobj_main = codeobj_0a96bfb0b3bb72ca71e8fbf1e1cbbeae;
n 108     codeobj_a3cd2cb40582c9dff826eafbf16b9e5f = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 108     codeobj_c035c0b708260fb973901a52c1a8698d = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
109     codeobj_fb65d31aaa3bbc288654f128bbb28377 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 109     codeobj_fb65d31aaa3bbc288654f128bbb28377 = 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_a3cd2cb40582c9dff826eafbf16b9e5f; 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_a3cd2cb40582c9dff826eafbf16b9e5f = 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_a3cd2cb40582c9dff826eafbf16b9e5f, codeobj_a3cd2cb40582c9dff826eafbf16b9e5f, module___main__, 0 ); n
300     frame_a3cd2cb40582c9dff826eafbf16b9e5f = cache_frame_a3cd2cb40582c9dff826eafbf16b9e5f;
301  
302     // Push the new frame as the currently active one.
303     pushFrameStack( frame_a3cd2cb40582c9dff826eafbf16b9e5f );
304  
305     // Mark the frame object as in use, ref count 1 will be up for reuse.
306     assert( Py_REFCNT( frame_a3cd2cb40582c9dff826eafbf16b9e5f ) == 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_a3cd2cb40582c9dff826eafbf16b9e5f->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_a3cd2cb40582c9dff826eafbf16b9e5f, 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_a3cd2cb40582c9dff826eafbf16b9e5f, 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_a3cd2cb40582c9dff826eafbf16b9e5f->m_frame) frame_a3cd2cb40582c9dff826eafbf16b9e5f->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_a3cd2cb40582c9dff826eafbf16b9e5f );
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_a3cd2cb40582c9dff826eafbf16b9e5f );
483 #endif
484  
485     if ( exception_tb == NULL )
486     {
487         exception_tb = MAKE_TRACEBACK( frame_a3cd2cb40582c9dff826eafbf16b9e5f, exception_lineno );
488     }
489     else if ( exception_tb->tb_frame != &frame_a3cd2cb40582c9dff826eafbf16b9e5f->m_frame )
490     {
491         exception_tb = ADD_TRACEBACK( exception_tb, frame_a3cd2cb40582c9dff826eafbf16b9e5f, exception_lineno );
492     }
493  
494     // Attachs locals to frame if any.
495     Nuitka_Frame_AttachLocals(
496         (struct Nuitka_FrameObject *)frame_a3cd2cb40582c9dff826eafbf16b9e5f,
497         type_description_1
498     );
499  
500  
501     // Release cached frame.
502     if ( frame_a3cd2cb40582c9dff826eafbf16b9e5f == cache_frame_a3cd2cb40582c9dff826eafbf16b9e5f )
503     {
504         Py_DECREF( frame_a3cd2cb40582c9dff826eafbf16b9e5f );
505     }
506     cache_frame_a3cd2cb40582c9dff826eafbf16b9e5f = NULL;
507  
508     assertFrameObject( frame_a3cd2cb40582c9dff826eafbf16b9e5f );
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_a3cd2cb40582c9dff826eafbf16b9e5f, n 333         codeobj_c035c0b708260fb973901a52c1a8698d,
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
1148             exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 905             exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
1149             exception_tb = NULL; 906             exception_tb = NULL;
1150             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 907             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
1151             CHAIN_EXCEPTION( exception_value ); 908             CHAIN_EXCEPTION( exception_value );
1152 909
n 1153             exception_lineno = 46; n 910             exception_lineno = 48;
1154 911
1155             goto frame_exception_exit_1; 912             goto frame_exception_exit_1;
1156         } 913         }
1157 914
1158         tmp_compexpr_left_1 = tmp_mvar_value_3; 915         tmp_compexpr_left_1 = tmp_mvar_value_3;
n 1159         tmp_compexpr_right_1 = const_int_pos_50000; n 916         tmp_compexpr_right_1 = const_int_0;
1160         tmp_operand_name_1 = RICH_COMPARE_EQ_OBJECT_OBJECT_NORECURSE( tmp_compexpr_left_1, tmp_compexpr_right_1 ); 917         tmp_operand_name_1 = RICH_COMPARE_EQ_OBJECT_OBJECT_NORECURSE( tmp_compexpr_left_1, tmp_compexpr_right_1 );
1161         if ( tmp_operand_name_1 == NULL ) 918         if ( tmp_operand_name_1 == NULL )
1162         { 919         {
1163             assert( ERROR_OCCURRED() ); 920             assert( ERROR_OCCURRED() );
1164 921
1165             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 922             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1166 923
1167 924
n 1168             exception_lineno = 46; n 925             exception_lineno = 48;
1169 926
1170             goto frame_exception_exit_1; 927             goto frame_exception_exit_1;
1171         } 928         }
1172         tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 ); 929         tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
1173         Py_DECREF( tmp_operand_name_1 ); 930         Py_DECREF( tmp_operand_name_1 );
1176             assert( ERROR_OCCURRED() ); 933             assert( ERROR_OCCURRED() );
1177 934
1178             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 935             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1179 936
1180 937
n 1181             exception_lineno = 46; n 938             exception_lineno = 48;
1182 939
1183             goto frame_exception_exit_1; 940             goto frame_exception_exit_1;
1184         } 941         }
1185         tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE; 942         tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1186         if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE ) 943         if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
1195         { 952         {
1196             PyObject *tmp_raise_type_1; 953             PyObject *tmp_raise_type_1;
1197             tmp_raise_type_1 = PyExc_AssertionError; 954             tmp_raise_type_1 = PyExc_AssertionError;
1198             exception_type = tmp_raise_type_1; 955             exception_type = tmp_raise_type_1;
1199             Py_INCREF( tmp_raise_type_1 ); 956             Py_INCREF( tmp_raise_type_1 );
t 1200             exception_lineno = 46; t 957             exception_lineno = 48;
1201             RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 958             RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
1202 959
1203             goto frame_exception_exit_1; 960             goto frame_exception_exit_1;
1204         } 961         }
1205         branch_no_1:; 962         branch_no_1:;