Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)48266334888.11538461538461257.0CPython 2.7173347988240.03846153846155415.36417757962045Nuitka (master)173347766391.96153846153845415.3642912398261Nuitka (develop)173347977543.8846153846154415.3641832114325Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)17681991988.11538461538461257.0CPython 3.5100594098240.03846153846155363.5297008423495Nuitka (master)100591472391.96153846153845363.5333708191466Nuitka (develop)100593544543.8846153846154363.530475087264Nuitka (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
94 } 94 }
95 #endif 95 #endif
96 96
97 // The module code objects. 97 // The module code objects.
98 static PyCodeObject *codeobj_d9ef85c2533b1cb35349c8650a6806d0; 98 static PyCodeObject *codeobj_d9ef85c2533b1cb35349c8650a6806d0;
n 99 static PyCodeObject *codeobj_cc70251ed8552af23748e20b701f05d4; n 99 static PyCodeObject *codeobj_92f168333bf4142bbc579f00e8011429;
100 static PyCodeObject *codeobj_5aed13a04991e7efb77675e667cf7c0c; 100 static PyCodeObject *codeobj_5aed13a04991e7efb77675e667cf7c0c;
101 /* For use in "MainProgram.c". */ 101 /* For use in "MainProgram.c". */
102 PyCodeObject *codeobj_main = NULL; 102 PyCodeObject *codeobj_main = NULL;
103 103
104 static void createModuleCodeObjects(void) 104 static void createModuleCodeObjects(void)
105 { 105 {
106     module_filename_obj = const_str_digest_4c6ebf7bc2c5731483e1e562bdc3bd21; 106     module_filename_obj = const_str_digest_4c6ebf7bc2c5731483e1e562bdc3bd21;
107     codeobj_d9ef85c2533b1cb35349c8650a6806d0 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 107     codeobj_d9ef85c2533b1cb35349c8650a6806d0 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
108     codeobj_main = codeobj_d9ef85c2533b1cb35349c8650a6806d0; 108     codeobj_main = codeobj_d9ef85c2533b1cb35349c8650a6806d0;
n 109     codeobj_cc70251ed8552af23748e20b701f05d4 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 109     codeobj_92f168333bf4142bbc579f00e8011429 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
110     codeobj_5aed13a04991e7efb77675e667cf7c0c = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 110     codeobj_5aed13a04991e7efb77675e667cf7c0c = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE );
111 } 111 }
112 112
113 // The module function declarations. 113 // The module function declarations.
114 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  ); 114 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  );
263 #ifndef __NUITKA_NO_ASSERT__ 263 #ifndef __NUITKA_NO_ASSERT__
264     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 264     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
265 #endif 265 #endif
266 266
267     // Local variable declarations. 267     // Local variable declarations.
n 268     PyObject *exception_type = NULL; n
269     PyObject *exception_value = NULL;
270     PyTracebackObject *exception_tb = NULL;
271     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
272     PyObject *exception_keeper_type_1;
273     PyObject *exception_keeper_value_1;
274     PyTracebackObject *exception_keeper_tb_1;
275     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
276     PyObject *exception_keeper_type_2;
277     PyObject *exception_keeper_value_2;
278     PyTracebackObject *exception_keeper_tb_2;
279     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
280     PyObject *exception_preserved_type_1;
281     PyObject *exception_preserved_value_1;
282     PyTracebackObject *exception_preserved_tb_1;
283     PyObject *tmp_called_name_1;
284     PyObject *tmp_compare_left_1;
285     PyObject *tmp_compare_right_1;
286     int tmp_exc_match_exception_match_1;
287     bool tmp_result;
288     PyObject *tmp_return_value; 268     PyObject *tmp_return_value;
n 289     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
290     static struct Nuitka_FrameObject *cache_frame_cc70251ed8552af23748e20b701f05d4 = NULL;
291  
292     struct Nuitka_FrameObject *frame_cc70251ed8552af23748e20b701f05d4;
293  
294     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
295     tmp_return_value = NULL; 269     tmp_return_value = NULL;
296 270
297     // Actual function code. 271     // Actual function code.
n 298     MAKE_OR_REUSE_FRAME( cache_frame_cc70251ed8552af23748e20b701f05d4, codeobj_cc70251ed8552af23748e20b701f05d4, module___main__, 0 ); n
299     frame_cc70251ed8552af23748e20b701f05d4 = cache_frame_cc70251ed8552af23748e20b701f05d4;
300  
301     // Push the new frame as the currently active one.
302     pushFrameStack( frame_cc70251ed8552af23748e20b701f05d4 );
303  
304     // Mark the frame object as in use, ref count 1 will be up for reuse.
305     assert( Py_REFCNT( frame_cc70251ed8552af23748e20b701f05d4 ) == 2 ); // Frame stack
306  
307     // Framed code:
308     // Tried code:
309     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
310  
311     if (unlikely( tmp_called_name_1 == NULL ))
312     {
313         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
314     }
315  
316     if ( tmp_called_name_1 == NULL )
317     {
318  
319         exception_type = PyExc_NameError;
320         Py_INCREF( exception_type );
321         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
322         exception_tb = NULL;
323         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
324         CHAIN_EXCEPTION( exception_value );
325  
326         exception_lineno = 34;
327  
328         goto try_except_handler_1;
329     }
330  
331     frame_cc70251ed8552af23748e20b701f05d4->m_frame.f_lineno = 34;
332     tmp_unused = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
333     if ( tmp_unused == NULL )
334     {
335         assert( ERROR_OCCURRED() );
336  
337         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
338  
339  
340         exception_lineno = 34;
341  
342         goto try_except_handler_1;
343     }
344     Py_DECREF( tmp_unused );
345     goto try_end_1;
346     // Exception handler code:
347     try_except_handler_1:;
348     exception_keeper_type_1 = exception_type;
349     exception_keeper_value_1 = exception_value;
350     exception_keeper_tb_1 = exception_tb;
351     exception_keeper_lineno_1 = exception_lineno;
352     exception_type = NULL;
353     exception_value = NULL;
354     exception_tb = NULL;
355     exception_lineno = 0;
356  
357     // Preserve existing published exception.
358     exception_preserved_type_1 = PyThreadState_GET()->exc_type;
359     Py_XINCREF( exception_preserved_type_1 );
360     exception_preserved_value_1 = PyThreadState_GET()->exc_value;
361     Py_XINCREF( exception_preserved_value_1 );
362     exception_preserved_tb_1 = (PyTracebackObject *)PyThreadState_GET()->exc_traceback;
363     Py_XINCREF( exception_preserved_tb_1 );
364  
365     if ( exception_keeper_tb_1 == NULL )
366     {
367         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_cc70251ed8552af23748e20b701f05d4, exception_keeper_lineno_1 );
368     }
369     else if ( exception_keeper_lineno_1 != 0 )
370     {
371         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_cc70251ed8552af23748e20b701f05d4, exception_keeper_lineno_1 );
372     }
373  
374     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
375     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
376     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
377     // Tried code:
378     tmp_compare_left_1 = PyThreadState_GET()->exc_type;
379     tmp_compare_right_1 = PyExc_TypeError;
380     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
381     if ( tmp_exc_match_exception_match_1 == -1 )
382     {
383         assert( ERROR_OCCURRED() );
384  
385         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
386  
387  
388         exception_lineno = 35;
389  
390         goto try_except_handler_2;
391     }
392     if ( tmp_exc_match_exception_match_1 == 1 )
393     {
394         goto branch_no_1;
395     }
396     else
397     {
398         goto branch_yes_1;
399     }
400     branch_yes_1:;
401     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
402     if (unlikely( tmp_result == false ))
403     {
404         exception_lineno = 33;
405     }
406  
407     if (exception_tb && exception_tb->tb_frame == &frame_cc70251ed8552af23748e20b701f05d4->m_frame) frame_cc70251ed8552af23748e20b701f05d4->m_frame.f_lineno = exception_tb->tb_lineno;
408  
409     goto try_except_handler_2;
410     branch_no_1:;
411     goto try_end_2;
412     // Exception handler code:
413     try_except_handler_2:;
414     exception_keeper_type_2 = exception_type;
415     exception_keeper_value_2 = exception_value;
416     exception_keeper_tb_2 = exception_tb;
417     exception_keeper_lineno_2 = exception_lineno;
418     exception_type = NULL;
419     exception_value = NULL;
420     exception_tb = NULL;
421     exception_lineno = 0;
422  
423     // Restore previous exception.
424     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
425     // Re-raise.
426     exception_type = exception_keeper_type_2;
427     exception_value = exception_keeper_value_2;
428     exception_tb = exception_keeper_tb_2;
429     exception_lineno = exception_keeper_lineno_2;
430  
431     goto frame_exception_exit_1;
432     // End of try:
433     try_end_2:;
434     // Restore previous exception.
435     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
436     goto try_end_1;
437     // exception handler codes exits in all cases
438     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
439     return NULL;
440     // End of try:
441     try_end_1:;
442  
443 #if 1
444     RESTORE_FRAME_EXCEPTION( frame_cc70251ed8552af23748e20b701f05d4 );
445 #endif
446  
447     // Put the previous frame back on top.
448     popFrameStack();
449  
450     goto frame_no_exception_1;
451  
452     frame_exception_exit_1:;
453  
454 #if 1
455     RESTORE_FRAME_EXCEPTION( frame_cc70251ed8552af23748e20b701f05d4 );
456 #endif
457  
458     if ( exception_tb == NULL )
459     {
460         exception_tb = MAKE_TRACEBACK( frame_cc70251ed8552af23748e20b701f05d4, exception_lineno );
461     }
462     else if ( exception_tb->tb_frame != &frame_cc70251ed8552af23748e20b701f05d4->m_frame )
463     {
464         exception_tb = ADD_TRACEBACK( exception_tb, frame_cc70251ed8552af23748e20b701f05d4, exception_lineno );
465     }
466  
467     // Attachs locals to frame if any.
468     Nuitka_Frame_AttachLocals(
469         (struct Nuitka_FrameObject *)frame_cc70251ed8552af23748e20b701f05d4,
470         type_description_1
471     );
472  
473  
474     // Release cached frame.
475     if ( frame_cc70251ed8552af23748e20b701f05d4 == cache_frame_cc70251ed8552af23748e20b701f05d4 )
476     {
477         Py_DECREF( frame_cc70251ed8552af23748e20b701f05d4 );
478     }
479     cache_frame_cc70251ed8552af23748e20b701f05d4 = NULL;
480  
481     assertFrameObject( frame_cc70251ed8552af23748e20b701f05d4 );
482  
483     // Put the previous frame back on top.
484     popFrameStack();
485  
486     // Return the error.
487     goto function_exception_exit;
488  
489     frame_no_exception_1:;
490  
491     tmp_return_value = Py_None; 272     tmp_return_value = Py_None;
492     Py_INCREF( tmp_return_value ); 273     Py_INCREF( tmp_return_value );
493     goto function_return_exit; 274     goto function_return_exit;
494 275
495     // Return statement must have exited already. 276     // Return statement must have exited already.
496     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 277     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
497     return NULL; 278     return NULL;
498 279
n 499 function_exception_exit: n
500     assert( exception_type );
501     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
502  
503     return NULL;
504 function_return_exit: 280 function_return_exit:
505 281
506 CHECK_OBJECT( tmp_return_value ); 282 CHECK_OBJECT( tmp_return_value );
507 assert( had_error || !ERROR_OCCURRED() ); 283 assert( had_error || !ERROR_OCCURRED() );
508 return tmp_return_value; 284 return tmp_return_value;
542         impl___main__$$$function_2_calledRepeatedly, 318         impl___main__$$$function_2_calledRepeatedly,
543         const_str_plain_calledRepeatedly, 319         const_str_plain_calledRepeatedly,
544 #if PYTHON_VERSION >= 330 320 #if PYTHON_VERSION >= 330
545         NULL, 321         NULL,
546 #endif 322 #endif
n 547         codeobj_cc70251ed8552af23748e20b701f05d4, n 323         codeobj_92f168333bf4142bbc579f00e8011429,
548         NULL, 324         NULL,
549 #if PYTHON_VERSION >= 300 325 #if PYTHON_VERSION >= 300
550         NULL, 326         NULL,
551         const_dict_empty, 327         const_dict_empty,
552 #endif 328 #endif
1006         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 782         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
1007         exception_tb = NULL; 783         exception_tb = NULL;
1008         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 784         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
1009         CHAIN_EXCEPTION( exception_value ); 785         CHAIN_EXCEPTION( exception_value );
1010 786
n 1011         exception_lineno = 46; n 787         exception_lineno = 48;
1012 788
1013         goto frame_exception_exit_1; 789         goto frame_exception_exit_1;
1014     } 790     }
1015 791
n 1016     tmp_compare_right_1 = const_int_pos_50000; n 792     tmp_compare_right_1 = const_int_0;
1017     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 ); 793     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 );
1018     if ( tmp_cmp_Eq_1 == -1 ) 794     if ( tmp_cmp_Eq_1 == -1 )
1019     { 795     {
1020         assert( ERROR_OCCURRED() ); 796         assert( ERROR_OCCURRED() );
1021 797
1022         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 798         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1023 799
1024 800
n 1025         exception_lineno = 46; n 801         exception_lineno = 48;
1026 802
1027         goto frame_exception_exit_1; 803         goto frame_exception_exit_1;
1028     } 804     }
1029     if ( tmp_cmp_Eq_1 == 1 ) 805     if ( tmp_cmp_Eq_1 == 1 )
1030     { 806     {
1036     } 812     }
1037     branch_yes_1:; 813     branch_yes_1:;
1038     tmp_raise_type_1 = PyExc_AssertionError; 814     tmp_raise_type_1 = PyExc_AssertionError;
1039     exception_type = tmp_raise_type_1; 815     exception_type = tmp_raise_type_1;
1040     Py_INCREF( tmp_raise_type_1 ); 816     Py_INCREF( tmp_raise_type_1 );
t 1041     exception_lineno = 46; t 817     exception_lineno = 48;
1042     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 818     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
1043 819
1044     goto frame_exception_exit_1; 820     goto frame_exception_exit_1;
1045     branch_no_1:; 821     branch_no_1:;
1046     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print ); 822     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print );