Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)43336831588.11538461538461257.0CPython 2.7169749077240.03846153846155407.32102517782045Nuitka (master)169749595391.96153846153845407.32072980373607Nuitka (develop)169749589543.8846153846154407.32073322505755Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)17937832188.11538461538461257.0CPython 3.5101344010240.03846153846155364.5017241128126Nuitka (master)101338046391.96153846153845364.509940245875Nuitka (develop)101341682543.8846153846154364.5049312150543Nuitka (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_5a617b686d68ffd4536bcfe2afa1e911; 98 static PyCodeObject *codeobj_5a617b686d68ffd4536bcfe2afa1e911;
n 99 static PyCodeObject *codeobj_32429a53ec60275dfb9baef14a464cb9; n 99 static PyCodeObject *codeobj_4a78947e81c448ecb21d0fab2c970bb5;
100 static PyCodeObject *codeobj_f18669d31d305a252b11eaebba52b5c4; 100 static PyCodeObject *codeobj_f18669d31d305a252b11eaebba52b5c4;
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_25f8bdbe99265fb0026c9eab9b085264; 106     module_filename_obj = const_str_digest_25f8bdbe99265fb0026c9eab9b085264;
107     codeobj_5a617b686d68ffd4536bcfe2afa1e911 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 107     codeobj_5a617b686d68ffd4536bcfe2afa1e911 = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
108     codeobj_main = codeobj_5a617b686d68ffd4536bcfe2afa1e911; 108     codeobj_main = codeobj_5a617b686d68ffd4536bcfe2afa1e911;
n 109     codeobj_32429a53ec60275dfb9baef14a464cb9 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 109     codeobj_4a78947e81c448ecb21d0fab2c970bb5 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
110     codeobj_f18669d31d305a252b11eaebba52b5c4 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 110     codeobj_f18669d31d305a252b11eaebba52b5c4 = 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(  );
258 #ifndef __NUITKA_NO_ASSERT__ 258 #ifndef __NUITKA_NO_ASSERT__
259     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 259     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
260 #endif 260 #endif
261 261
262     // Local variable declarations. 262     // Local variable declarations.
n 263     PyObject *exception_type = NULL; n
264     PyObject *exception_value = NULL;
265     PyTracebackObject *exception_tb = NULL;
266     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
267     PyObject *exception_keeper_type_1;
268     PyObject *exception_keeper_value_1;
269     PyTracebackObject *exception_keeper_tb_1;
270     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
271     PyObject *exception_keeper_type_2;
272     PyObject *exception_keeper_value_2;
273     PyTracebackObject *exception_keeper_tb_2;
274     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
275     PyObject *exception_preserved_type_1;
276     PyObject *exception_preserved_value_1;
277     PyTracebackObject *exception_preserved_tb_1;
278     PyObject *tmp_called_name_1;
279     PyObject *tmp_compare_left_1;
280     PyObject *tmp_compare_right_1;
281     int tmp_exc_match_exception_match_1;
282     bool tmp_result;
283     PyObject *tmp_return_value; 263     PyObject *tmp_return_value;
n 284     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
285     static struct Nuitka_FrameObject *cache_frame_32429a53ec60275dfb9baef14a464cb9 = NULL;
286  
287     struct Nuitka_FrameObject *frame_32429a53ec60275dfb9baef14a464cb9;
288  
289     tmp_return_value = NULL; 264     tmp_return_value = NULL;
290 265
291     // Actual function code. 266     // Actual function code.
n 292     MAKE_OR_REUSE_FRAME( cache_frame_32429a53ec60275dfb9baef14a464cb9, codeobj_32429a53ec60275dfb9baef14a464cb9, module___main__, 0 ); n
293     frame_32429a53ec60275dfb9baef14a464cb9 = cache_frame_32429a53ec60275dfb9baef14a464cb9;
294  
295     // Push the new frame as the currently active one.
296     pushFrameStack( frame_32429a53ec60275dfb9baef14a464cb9 );
297  
298     // Mark the frame object as in use, ref count 1 will be up for reuse.
299     assert( Py_REFCNT( frame_32429a53ec60275dfb9baef14a464cb9 ) == 2 ); // Frame stack
300  
301     // Framed code:
302     // Tried code:
303     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
304  
305     if (unlikely( tmp_called_name_1 == NULL ))
306     {
307         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
308     }
309  
310     if ( tmp_called_name_1 == NULL )
311     {
312  
313         exception_type = PyExc_NameError;
314         Py_INCREF( exception_type );
315         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
316         exception_tb = NULL;
317         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
318         CHAIN_EXCEPTION( exception_value );
319  
320         exception_lineno = 34;
321  
322         goto try_except_handler_1;
323     }
324  
325     frame_32429a53ec60275dfb9baef14a464cb9->m_frame.f_lineno = 34;
326     tmp_unused = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
327     if ( tmp_unused == NULL )
328     {
329         assert( ERROR_OCCURRED() );
330  
331         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
332  
333  
334         exception_lineno = 34;
335  
336         goto try_except_handler_1;
337     }
338     Py_DECREF( tmp_unused );
339     goto try_end_1;
340     // Exception handler code:
341     try_except_handler_1:;
342     exception_keeper_type_1 = exception_type;
343     exception_keeper_value_1 = exception_value;
344     exception_keeper_tb_1 = exception_tb;
345     exception_keeper_lineno_1 = exception_lineno;
346     exception_type = NULL;
347     exception_value = NULL;
348     exception_tb = NULL;
349     exception_lineno = 0;
350  
351     // Preserve existing published exception.
352     exception_preserved_type_1 = PyThreadState_GET()->exc_type;
353     Py_XINCREF( exception_preserved_type_1 );
354     exception_preserved_value_1 = PyThreadState_GET()->exc_value;
355     Py_XINCREF( exception_preserved_value_1 );
356     exception_preserved_tb_1 = (PyTracebackObject *)PyThreadState_GET()->exc_traceback;
357     Py_XINCREF( exception_preserved_tb_1 );
358  
359     if ( exception_keeper_tb_1 == NULL )
360     {
361         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_32429a53ec60275dfb9baef14a464cb9, exception_keeper_lineno_1 );
362     }
363     else if ( exception_keeper_lineno_1 != 0 )
364     {
365         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_32429a53ec60275dfb9baef14a464cb9, exception_keeper_lineno_1 );
366     }
367  
368     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
369     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
370     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
371     // Tried code:
372     tmp_compare_left_1 = PyThreadState_GET()->exc_type;
373     tmp_compare_right_1 = PyExc_TypeError;
374     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
375     if ( tmp_exc_match_exception_match_1 == -1 )
376     {
377         assert( ERROR_OCCURRED() );
378  
379         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
380  
381  
382         exception_lineno = 35;
383  
384         goto try_except_handler_2;
385     }
386     if ( tmp_exc_match_exception_match_1 == 1 )
387     {
388         goto branch_no_1;
389     }
390     else
391     {
392         goto branch_yes_1;
393     }
394     branch_yes_1:;
395     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
396     if (unlikely( tmp_result == false ))
397     {
398         exception_lineno = 33;
399     }
400  
401     if (exception_tb && exception_tb->tb_frame == &frame_32429a53ec60275dfb9baef14a464cb9->m_frame) frame_32429a53ec60275dfb9baef14a464cb9->m_frame.f_lineno = exception_tb->tb_lineno;
402  
403     goto try_except_handler_2;
404     branch_no_1:;
405     goto try_end_2;
406     // Exception handler code:
407     try_except_handler_2:;
408     exception_keeper_type_2 = exception_type;
409     exception_keeper_value_2 = exception_value;
410     exception_keeper_tb_2 = exception_tb;
411     exception_keeper_lineno_2 = exception_lineno;
412     exception_type = NULL;
413     exception_value = NULL;
414     exception_tb = NULL;
415     exception_lineno = 0;
416  
417     // Restore previous exception.
418     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
419     // Re-raise.
420     exception_type = exception_keeper_type_2;
421     exception_value = exception_keeper_value_2;
422     exception_tb = exception_keeper_tb_2;
423     exception_lineno = exception_keeper_lineno_2;
424  
425     goto frame_exception_exit_1;
426     // End of try:
427     try_end_2:;
428     // Restore previous exception.
429     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
430     goto try_end_1;
431     // exception handler codes exits in all cases
432     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
433     return NULL;
434     // End of try:
435     try_end_1:;
436  
437 #if 1
438     RESTORE_FRAME_EXCEPTION( frame_32429a53ec60275dfb9baef14a464cb9 );
439 #endif
440  
441     // Put the previous frame back on top.
442     popFrameStack();
443  
444     goto frame_no_exception_1;
445  
446     frame_exception_exit_1:;
447  
448 #if 1
449     RESTORE_FRAME_EXCEPTION( frame_32429a53ec60275dfb9baef14a464cb9 );
450 #endif
451  
452     if ( exception_tb == NULL )
453     {
454         exception_tb = MAKE_TRACEBACK( frame_32429a53ec60275dfb9baef14a464cb9, exception_lineno );
455     }
456     else if ( exception_tb->tb_frame != &frame_32429a53ec60275dfb9baef14a464cb9->m_frame )
457     {
458         exception_tb = ADD_TRACEBACK( exception_tb, frame_32429a53ec60275dfb9baef14a464cb9, exception_lineno );
459     }
460  
461     Nuitka_Frame_AttachLocals( (struct Nuitka_FrameObject *)frame_32429a53ec60275dfb9baef14a464cb9, ""  );
462  
463     // Release cached frame.
464     if ( frame_32429a53ec60275dfb9baef14a464cb9 == cache_frame_32429a53ec60275dfb9baef14a464cb9 )
465     {
466         Py_DECREF( frame_32429a53ec60275dfb9baef14a464cb9 );
467     }
468     cache_frame_32429a53ec60275dfb9baef14a464cb9 = NULL;
469  
470     assertFrameObject( frame_32429a53ec60275dfb9baef14a464cb9 );
471  
472  
473     // Put the previous frame back on top.
474     popFrameStack();
475  
476     // Return the error.
477     goto function_exception_exit;
478  
479     frame_no_exception_1:;
480  
481     tmp_return_value = Py_None; 267     tmp_return_value = Py_None;
482     Py_INCREF( tmp_return_value ); 268     Py_INCREF( tmp_return_value );
483     goto function_return_exit; 269     goto function_return_exit;
484 270
485     // Return statement must have exited already. 271     // Return statement must have exited already.
486     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 272     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
487     return NULL; 273     return NULL;
488 274
n 489 function_exception_exit: n
490     assert( exception_type );
491     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
492  
493     return NULL;
494     function_return_exit: 275     function_return_exit:
495 276
496     CHECK_OBJECT( tmp_return_value ); 277     CHECK_OBJECT( tmp_return_value );
497     assert( had_error || !ERROR_OCCURRED() ); 278     assert( had_error || !ERROR_OCCURRED() );
498     return tmp_return_value; 279     return tmp_return_value;
532         impl___main__$$$function_2_calledRepeatedly, 313         impl___main__$$$function_2_calledRepeatedly,
533         const_str_plain_calledRepeatedly, 314         const_str_plain_calledRepeatedly,
534 #if PYTHON_VERSION >= 330 315 #if PYTHON_VERSION >= 330
535         NULL, 316         NULL,
536 #endif 317 #endif
n 537         codeobj_32429a53ec60275dfb9baef14a464cb9, n 318         codeobj_4a78947e81c448ecb21d0fab2c970bb5,
538         NULL, 319         NULL,
539 #if PYTHON_VERSION >= 300 320 #if PYTHON_VERSION >= 300
540         NULL, 321         NULL,
541         const_dict_empty, 322         const_dict_empty,
542 #endif 323 #endif
985         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 766         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
986         exception_tb = NULL; 767         exception_tb = NULL;
987         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 768         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
988         CHAIN_EXCEPTION( exception_value ); 769         CHAIN_EXCEPTION( exception_value );
989 770
n 990         exception_lineno = 46; n 771         exception_lineno = 48;
991 772
992         goto frame_exception_exit_1; 773         goto frame_exception_exit_1;
993     } 774     }
994 775
n 995     tmp_compare_right_1 = const_int_pos_50000; n 776     tmp_compare_right_1 = const_int_0;
996     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 ); 777     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 );
997     if ( tmp_cmp_Eq_1 == -1 ) 778     if ( tmp_cmp_Eq_1 == -1 )
998     { 779     {
999         assert( ERROR_OCCURRED() ); 780         assert( ERROR_OCCURRED() );
1000 781
1001         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 782         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
1002 783
1003 784
n 1004         exception_lineno = 46; n 785         exception_lineno = 48;
1005 786
1006         goto frame_exception_exit_1; 787         goto frame_exception_exit_1;
1007     } 788     }
1008     if ( tmp_cmp_Eq_1 == 1 ) 789     if ( tmp_cmp_Eq_1 == 1 )
1009     { 790     {
1015     } 796     }
1016     branch_yes_1:; 797     branch_yes_1:;
1017     tmp_raise_type_1 = PyExc_AssertionError; 798     tmp_raise_type_1 = PyExc_AssertionError;
1018     exception_type = tmp_raise_type_1; 799     exception_type = tmp_raise_type_1;
1019     Py_INCREF( tmp_raise_type_1 ); 800     Py_INCREF( tmp_raise_type_1 );
t 1020     exception_lineno = 46; t 801     exception_lineno = 48;
1021     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 802     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
1022 803
1023     goto frame_exception_exit_1; 804     goto frame_exception_exit_1;
1024     branch_no_1:; 805     branch_no_1:;
1025     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print ); 806     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print );