Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)43325352172.9230769230769257.0CPython 2.7196178697194.46153846153845392.2206813695684Nuitka (historic)181048960316.0400.8502495015366Nuitka (master)169749454437.53846153846143407.29516370490865Nuitka (develop)169748554559.0769230769231407.2956770391007Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)17517864172.9230769230769257.0CPython 3.50194.46153846153845504.11538461538464Nuitka (historic)114724469316.0342.27955166283436Nuitka (master)99938267437.53846153846143363.13767667951817Nuitka (develop)99935284559.0769230769231363.14188464224753Nuitka (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



for x in xrange(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

for x in xrange(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 for x in xrange(50000): 41 for x in xrange(50000):
42     calledRepeatedly() 42     calledRepeatedly()
43 43
44 # construct_begin 44 # construct_begin
n 45 assert count == 50000 n 45  
46 # construct_alternative 46 # construct_alternative
t 47   t 47 assert count == 0
48   48 # construct_end
49 print("OK.") 49 print("OK.")
50 50

Context Diff of Generated Code


Construct
Baseline
41 static PyObject *const_str_angle_module; 41 static PyObject *const_str_angle_module;
42 static PyObject *const_xrange_0_50000; 42 static PyObject *const_xrange_0_50000;
43 static PyObject *const_str_plain_x; 43 static PyObject *const_str_plain_x;
44 static PyObject *const_str_plain_raisy; 44 static PyObject *const_str_plain_raisy;
45 extern PyObject *const_str_plain_print; 45 extern PyObject *const_str_plain_print;
n 46 static PyObject *const_int_pos_50000; n 46 extern PyObject *const_int_pos_1;
47 extern PyObject *const_str_plain___doc__; 47 extern PyObject *const_str_plain___doc__;
48 extern PyObject *const_str_plain___cached__; 48 extern PyObject *const_str_plain___cached__;
n 49 extern PyObject *const_int_pos_1; n
50 extern PyObject *const_tuple_empty; 49 extern PyObject *const_tuple_empty;
n n 50 static PyObject *const_int_pos_50000;
51 static PyObject *const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple; 51 static PyObject *const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple;
52 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352; 52 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352;
53 extern PyObject *const_dict_empty; 53 extern PyObject *const_dict_empty;
54 static PyObject *module_filename_obj; 54 static PyObject *module_filename_obj;
55 55
83 } 83 }
84 #endif 84 #endif
85 85
86 // The module code objects. 86 // The module code objects.
87 static PyCodeObject *codeobj_9cb27ef200eaf84cb9819e805f10c8ae; 87 static PyCodeObject *codeobj_9cb27ef200eaf84cb9819e805f10c8ae;
n 88 static PyCodeObject *codeobj_c238daa98569e451e7b6f2ea8fc5fa57; n 88 static PyCodeObject *codeobj_b91ca7dc19ecfbeb7e9b5d9d766d5fe4;
89 static PyCodeObject *codeobj_162ff8f85417317d55457fcac335e04f; 89 static PyCodeObject *codeobj_162ff8f85417317d55457fcac335e04f;
90 /* For use in "MainProgram.c". */ 90 /* For use in "MainProgram.c". */
91 PyCodeObject *codeobj_main = NULL; 91 PyCodeObject *codeobj_main = NULL;
92 92
93 static void createModuleCodeObjects(void) 93 static void createModuleCodeObjects(void)
94 { 94 {
95     module_filename_obj = const_str_digest_66ac19f301ff4cec782494cdcb8c84ac; 95     module_filename_obj = const_str_digest_66ac19f301ff4cec782494cdcb8c84ac;
96     codeobj_9cb27ef200eaf84cb9819e805f10c8ae = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE ); 96     codeobj_9cb27ef200eaf84cb9819e805f10c8ae = MAKE_CODEOBJ( module_filename_obj, const_str_angle_module, 1, const_tuple_empty, 0, 0, CO_NOFREE );
97     codeobj_main = codeobj_9cb27ef200eaf84cb9819e805f10c8ae; 97     codeobj_main = codeobj_9cb27ef200eaf84cb9819e805f10c8ae;
n 98     codeobj_c238daa98569e451e7b6f2ea8fc5fa57 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); n 98     codeobj_b91ca7dc19ecfbeb7e9b5d9d766d5fe4 = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 31, const_tuple_empty, 0, 0, CO_NOFREE );
99     codeobj_162ff8f85417317d55457fcac335e04f = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 99     codeobj_162ff8f85417317d55457fcac335e04f = MAKE_CODEOBJ( module_filename_obj, const_str_plain_raisy, 25, const_tuple_empty, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE );
100 } 100 }
101 101
102 // The module function declarations. 102 // The module function declarations.
103 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  ); 103 static PyObject *MAKE_FUNCTION___main__$$$function_1_raisy(  );
246 #ifndef __NUITKA_NO_ASSERT__ 246 #ifndef __NUITKA_NO_ASSERT__
247     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 247     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
248 #endif 248 #endif
249 249
250     // Local variable declarations. 250     // Local variable declarations.
n 251     PyObject *exception_type = NULL, *exception_value = NULL; n
252     PyTracebackObject *exception_tb = NULL;
253     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
254     PyObject *exception_keeper_type_1;
255     PyObject *exception_keeper_value_1;
256     PyTracebackObject *exception_keeper_tb_1;
257     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
258     PyObject *exception_keeper_type_2;
259     PyObject *exception_keeper_value_2;
260     PyTracebackObject *exception_keeper_tb_2;
261     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
262     PyObject *exception_preserved_type_1;
263     PyObject *exception_preserved_value_1;
264     PyTracebackObject *exception_preserved_tb_1;
265     PyObject *tmp_called_name_1;
266     PyObject *tmp_compare_left_1;
267     PyObject *tmp_compare_right_1;
268     int tmp_exc_match_exception_match_1;
269     PyObject *tmp_return_value; 251     PyObject *tmp_return_value;
n 270     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
271     static struct Nuitka_FrameObject *cache_frame_c238daa98569e451e7b6f2ea8fc5fa57 = NULL;
272  
273     struct Nuitka_FrameObject *frame_c238daa98569e451e7b6f2ea8fc5fa57;
274  
275     tmp_return_value = NULL; 252     tmp_return_value = NULL;
276 253
277     // Actual function code. 254     // Actual function code.
n 278     MAKE_OR_REUSE_FRAME( cache_frame_c238daa98569e451e7b6f2ea8fc5fa57, codeobj_c238daa98569e451e7b6f2ea8fc5fa57, module___main__, 0 ); n
279     frame_c238daa98569e451e7b6f2ea8fc5fa57 = cache_frame_c238daa98569e451e7b6f2ea8fc5fa57;
280  
281     // Push the new frame as the currently active one.
282     pushFrameStack( frame_c238daa98569e451e7b6f2ea8fc5fa57 );
283  
284     // Mark the frame object as in use, ref count 1 will be up for reuse.
285     assert( Py_REFCNT( frame_c238daa98569e451e7b6f2ea8fc5fa57 ) == 2 ); // Frame stack
286  
287     // Framed code:
288     // Tried code:
289     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
290  
291     if (unlikely( tmp_called_name_1 == NULL ))
292     {
293         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
294     }
295  
296     if ( tmp_called_name_1 == NULL )
297     {
298  
299         exception_type = PyExc_NameError;
300         Py_INCREF( exception_type );
301         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
302         exception_tb = NULL;
303         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
304         CHAIN_EXCEPTION( exception_value );
305  
306         exception_lineno = 34;
307  
308         goto try_except_handler_1;
309     }
310  
311     frame_c238daa98569e451e7b6f2ea8fc5fa57->m_frame.f_lineno = 34;
312     tmp_unused = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
313     if ( tmp_unused == NULL )
314     {
315         assert( ERROR_OCCURRED() );
316  
317         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
318  
319  
320         exception_lineno = 34;
321  
322         goto try_except_handler_1;
323     }
324     Py_DECREF( tmp_unused );
325     goto try_end_1;
326     // Exception handler code:
327     try_except_handler_1:;
328     exception_keeper_type_1 = exception_type;
329     exception_keeper_value_1 = exception_value;
330     exception_keeper_tb_1 = exception_tb;
331     exception_keeper_lineno_1 = exception_lineno;
332     exception_type = NULL;
333     exception_value = NULL;
334     exception_tb = NULL;
335     exception_lineno = -1;
336  
337     // Preserve existing published exception.
338     exception_preserved_type_1 = PyThreadState_GET()->exc_type;
339     Py_XINCREF( exception_preserved_type_1 );
340     exception_preserved_value_1 = PyThreadState_GET()->exc_value;
341     Py_XINCREF( exception_preserved_value_1 );
342     exception_preserved_tb_1 = (PyTracebackObject *)PyThreadState_GET()->exc_traceback;
343     Py_XINCREF( exception_preserved_tb_1 );
344  
345     if ( exception_keeper_tb_1 == NULL )
346     {
347         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_c238daa98569e451e7b6f2ea8fc5fa57, exception_keeper_lineno_1 );
348     }
349     else if ( exception_keeper_lineno_1 != -1 )
350     {
351         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_c238daa98569e451e7b6f2ea8fc5fa57, exception_keeper_lineno_1 );
352     }
353  
354     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
355     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
356     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
357     // Tried code:
358     tmp_compare_left_1 = PyThreadState_GET()->exc_type;
359     tmp_compare_right_1 = PyExc_TypeError;
360     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
361     if ( tmp_exc_match_exception_match_1 == -1 )
362     {
363         assert( ERROR_OCCURRED() );
364  
365         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
366  
367  
368         exception_lineno = 35;
369  
370         goto try_except_handler_2;
371     }
372     if ( tmp_exc_match_exception_match_1 == 1 )
373     {
374         goto branch_no_1;
375     }
376     else
377     {
378         goto branch_yes_1;
379     }
380     branch_yes_1:;
381     RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
382     if (exception_tb && exception_tb->tb_frame == &frame_c238daa98569e451e7b6f2ea8fc5fa57->m_frame) frame_c238daa98569e451e7b6f2ea8fc5fa57->m_frame.f_lineno = exception_tb->tb_lineno;
383  
384     goto try_except_handler_2;
385     branch_no_1:;
386     goto try_end_2;
387     // Exception handler code:
388     try_except_handler_2:;
389     exception_keeper_type_2 = exception_type;
390     exception_keeper_value_2 = exception_value;
391     exception_keeper_tb_2 = exception_tb;
392     exception_keeper_lineno_2 = exception_lineno;
393     exception_type = NULL;
394     exception_value = NULL;
395     exception_tb = NULL;
396     exception_lineno = -1;
397  
398     // Restore previous exception.
399     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
400     // Re-raise.
401     exception_type = exception_keeper_type_2;
402     exception_value = exception_keeper_value_2;
403     exception_tb = exception_keeper_tb_2;
404     exception_lineno = exception_keeper_lineno_2;
405  
406     goto frame_exception_exit_1;
407     // End of try:
408     try_end_2:;
409     // Restore previous exception.
410     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
411     goto try_end_1;
412     // exception handler codes exits in all cases
413     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
414     return NULL;
415     // End of try:
416     try_end_1:;
417  
418 #if 1
419     RESTORE_FRAME_EXCEPTION( frame_c238daa98569e451e7b6f2ea8fc5fa57 );
420 #endif
421  
422     // Put the previous frame back on top.
423     popFrameStack();
424  
425     goto frame_no_exception_1;
426  
427     frame_exception_exit_1:;
428  
429 #if 1
430     RESTORE_FRAME_EXCEPTION( frame_c238daa98569e451e7b6f2ea8fc5fa57 );
431 #endif
432  
433     if ( exception_tb == NULL )
434     {
435         exception_tb = MAKE_TRACEBACK( frame_c238daa98569e451e7b6f2ea8fc5fa57, exception_lineno );
436     }
437     else if ( exception_tb->tb_frame != &frame_c238daa98569e451e7b6f2ea8fc5fa57->m_frame )
438     {
439         exception_tb = ADD_TRACEBACK( exception_tb, frame_c238daa98569e451e7b6f2ea8fc5fa57, exception_lineno );
440     }
441  
442     Nuitka_Frame_AttachLocals( (struct Nuitka_FrameObject *)frame_c238daa98569e451e7b6f2ea8fc5fa57, ""  );
443  
444     // Release cached frame.
445     if ( frame_c238daa98569e451e7b6f2ea8fc5fa57 == cache_frame_c238daa98569e451e7b6f2ea8fc5fa57 )
446     {
447         Py_DECREF( frame_c238daa98569e451e7b6f2ea8fc5fa57 );
448     }
449     cache_frame_c238daa98569e451e7b6f2ea8fc5fa57 = NULL;
450  
451     assertFrameObject( frame_c238daa98569e451e7b6f2ea8fc5fa57 );
452  
453  
454     // Put the previous frame back on top.
455     popFrameStack();
456  
457     // Return the error.
458     goto function_exception_exit;
459  
460     frame_no_exception_1:;
461  
462     tmp_return_value = Py_None; 255     tmp_return_value = Py_None;
463     Py_INCREF( tmp_return_value ); 256     Py_INCREF( tmp_return_value );
464     goto function_return_exit; 257     goto function_return_exit;
465 258
466     // Return statement must have exited already. 259     // Return statement must have exited already.
467     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 260     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
468     return NULL; 261     return NULL;
469 262
n 470 function_exception_exit: n
471     assert( exception_type );
472     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
473  
474     return NULL;
475     function_return_exit: 263     function_return_exit:
476 264
477     CHECK_OBJECT( tmp_return_value ); 265     CHECK_OBJECT( tmp_return_value );
478     assert( had_error || !ERROR_OCCURRED() ); 266     assert( had_error || !ERROR_OCCURRED() );
479     return tmp_return_value; 267     return tmp_return_value;
513         impl___main__$$$function_2_calledRepeatedly, 301         impl___main__$$$function_2_calledRepeatedly,
514         const_str_plain_calledRepeatedly, 302         const_str_plain_calledRepeatedly,
515 #if PYTHON_VERSION >= 330 303 #if PYTHON_VERSION >= 330
516         NULL, 304         NULL,
517 #endif 305 #endif
n 518         codeobj_c238daa98569e451e7b6f2ea8fc5fa57, n 306         codeobj_b91ca7dc19ecfbeb7e9b5d9d766d5fe4,
519         NULL, 307         NULL,
520 #if PYTHON_VERSION >= 300 308 #if PYTHON_VERSION >= 300
521         NULL, 309         NULL,
522         const_dict_empty, 310         const_dict_empty,
523 #endif 311 #endif
894         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 682         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
895         exception_tb = NULL; 683         exception_tb = NULL;
896         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 684         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
897         CHAIN_EXCEPTION( exception_value ); 685         CHAIN_EXCEPTION( exception_value );
898 686
n 899         exception_lineno = 45; n 687         exception_lineno = 47;
900 688
901         goto frame_exception_exit_1; 689         goto frame_exception_exit_1;
902     } 690     }
903 691
n 904     tmp_compare_right_1 = const_int_pos_50000; n 692     tmp_compare_right_1 = const_int_0;
905     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 ); 693     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 );
906     if ( tmp_cmp_Eq_1 == -1 ) 694     if ( tmp_cmp_Eq_1 == -1 )
907     { 695     {
908         assert( ERROR_OCCURRED() ); 696         assert( ERROR_OCCURRED() );
909 697
910         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 698         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
911 699
912 700
n 913         exception_lineno = 45; n 701         exception_lineno = 47;
914 702
915         goto frame_exception_exit_1; 703         goto frame_exception_exit_1;
916     } 704     }
917     if ( tmp_cmp_Eq_1 == 1 ) 705     if ( tmp_cmp_Eq_1 == 1 )
918     { 706     {
924     } 712     }
925     branch_yes_1:; 713     branch_yes_1:;
926     tmp_raise_type_1 = PyExc_AssertionError; 714     tmp_raise_type_1 = PyExc_AssertionError;
927     exception_type = tmp_raise_type_1; 715     exception_type = tmp_raise_type_1;
928     Py_INCREF( tmp_raise_type_1 ); 716     Py_INCREF( tmp_raise_type_1 );
t 929     exception_lineno = 45; t 717     exception_lineno = 47;
930     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 718     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
931 719
932     goto frame_exception_exit_1; 720     goto frame_exception_exit_1;
933     branch_no_1:; 721     branch_no_1:;
934     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print ); 722     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print );