Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)43325352172.9230769230769257.0CPython 2.7196178697194.46153846153845392.2206813695684Nuitka (historic)190935396316.0395.21130990567036Nuitka (master)193985250437.53846153846143393.4717606401705Nuitka (develop)193985274559.0769230769231393.47174695125875Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)17517864172.9230769230769257.0CPython 3.50194.46153846153845504.11538461538464Nuitka (historic)148037453316.0295.2866602529384Nuitka (master)151186360437.53846153846143290.8446611600063Nuitka (develop)151185782559.0769230769231290.84547651450094Nuitka (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
261 #ifndef __NUITKA_NO_ASSERT__ 261 #ifndef __NUITKA_NO_ASSERT__
262     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 262     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
263 #endif 263 #endif
264 264
265     // Local variable declarations. 265     // Local variable declarations.
n 266     PyObject *exception_type = NULL, *exception_value = NULL; n
267     PyTracebackObject *exception_tb = NULL;
268     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
269     PyObject *exception_keeper_type_1;
270     PyObject *exception_keeper_value_1;
271     PyTracebackObject *exception_keeper_tb_1;
272     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
273     PyObject *exception_keeper_type_2;
274     PyObject *exception_keeper_value_2;
275     PyTracebackObject *exception_keeper_tb_2;
276     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
277     PyObject *exception_preserved_type_1;
278     PyObject *exception_preserved_value_1;
279     PyTracebackObject *exception_preserved_tb_1;
280     PyObject *tmp_called_name_1;
281     PyObject *tmp_compare_left_1;
282     PyObject *tmp_compare_right_1;
283     int tmp_exc_match_exception_match_1;
284     PyObject *tmp_frame_locals;
285     PyObject *tmp_return_value; 266     PyObject *tmp_return_value;
n 286     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
287     static PyFrameObject *cache_frame_function = NULL;
288  
289     PyFrameObject *frame_function;
290  
291     tmp_return_value = NULL; 267     tmp_return_value = NULL;
292 268
293     // Actual function code. 269     // Actual function code.
n 294     MAKE_OR_REUSE_FRAME( cache_frame_function, codeobj_aaf3ee67718fc0d92703818d40724525, module___main__ ); n
295     frame_function = cache_frame_function;
296  
297     // Push the new frame as the currently active one.
298     pushFrameStack( frame_function );
299  
300     // Mark the frame object as in use, ref count 1 will be up for reuse.
301     Py_INCREF( frame_function );
302     assert( Py_REFCNT( frame_function ) == 2 ); // Frame stack
303  
304 #if PYTHON_VERSION >= 340
305     frame_function->f_executing += 1;
306 #endif
307  
308     // Framed code:
309     // Tried code:
310     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
311  
312     if (unlikely( tmp_called_name_1 == NULL ))
313     {
314         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
315     }
316  
317     if ( tmp_called_name_1 == NULL )
318     {
319  
320         exception_type = PyExc_NameError;
321         Py_INCREF( exception_type );
322         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
323         exception_tb = NULL;
324         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
325         CHAIN_EXCEPTION( exception_value );
326  
327         exception_lineno = 34;
328         goto try_except_handler_1;
329     }
330  
331     frame_function->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         goto try_except_handler_1;
342     }
343     Py_DECREF( tmp_unused );
344     goto try_end_1;
345     // Exception handler code:
346     try_except_handler_1:;
347     exception_keeper_type_1 = exception_type;
348     exception_keeper_value_1 = exception_value;
349     exception_keeper_tb_1 = exception_tb;
350     exception_keeper_lineno_1 = exception_lineno;
351     exception_type = NULL;
352     exception_value = NULL;
353     exception_tb = NULL;
354     exception_lineno = -1;
355  
356     // Preserve existing published exception.
357     exception_preserved_type_1 = PyThreadState_GET()->exc_type;
358     Py_XINCREF( exception_preserved_type_1 );
359     exception_preserved_value_1 = PyThreadState_GET()->exc_value;
360     Py_XINCREF( exception_preserved_value_1 );
361     exception_preserved_tb_1 = (PyTracebackObject *)PyThreadState_GET()->exc_traceback;
362     Py_XINCREF( exception_preserved_tb_1 );
363  
364     if ( exception_keeper_tb_1 == NULL )
365     {
366         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_function, exception_keeper_lineno_1 );
367     }
368     else if ( exception_keeper_lineno_1 != -1 )
369     {
370         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_function, exception_keeper_lineno_1 );
371     }
372  
373     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
374     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
375     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
376     // Tried code:
377     tmp_compare_left_1 = PyThreadState_GET()->exc_type;
378     tmp_compare_right_1 = PyExc_TypeError;
379     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
380     if ( tmp_exc_match_exception_match_1 == -1 )
381     {
382         assert( ERROR_OCCURRED() );
383  
384         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
385  
386  
387         exception_lineno = 35;
388         goto try_except_handler_2;
389     }
390     if ( tmp_exc_match_exception_match_1 == 1 )
391     {
392         goto branch_no_1;
393     }
394     else
395     {
396         goto branch_yes_1;
397     }
398     branch_yes_1:;
399     RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
400     if (exception_tb && exception_tb->tb_frame == frame_function) frame_function->f_lineno = exception_tb->tb_lineno;
401     goto try_except_handler_2;
402     branch_no_1:;
403     goto try_end_2;
404     // Exception handler code:
405     try_except_handler_2:;
406     exception_keeper_type_2 = exception_type;
407     exception_keeper_value_2 = exception_value;
408     exception_keeper_tb_2 = exception_tb;
409     exception_keeper_lineno_2 = exception_lineno;
410     exception_type = NULL;
411     exception_value = NULL;
412     exception_tb = NULL;
413     exception_lineno = -1;
414  
415     // Restore previous exception.
416     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
417     // Re-raise.
418     exception_type = exception_keeper_type_2;
419     exception_value = exception_keeper_value_2;
420     exception_tb = exception_keeper_tb_2;
421     exception_lineno = exception_keeper_lineno_2;
422  
423     goto frame_exception_exit_1;
424     // End of try:
425     try_end_2:;
426     // Restore previous exception.
427     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
428     goto try_end_1;
429     // exception handler codes exits in all cases
430     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
431     return NULL;
432     // End of try:
433     try_end_1:;
434  
435 #if 1
436     RESTORE_FRAME_EXCEPTION( frame_function );
437 #endif
438     // Put the previous frame back on top.
439     popFrameStack();
440 #if PYTHON_VERSION >= 340
441     frame_function->f_executing -= 1;
442 #endif
443     Py_DECREF( frame_function );
444     goto frame_no_exception_1;
445  
446     frame_exception_exit_1:;
447 #if 1
448     RESTORE_FRAME_EXCEPTION( frame_function );
449 #endif
450  
451     {
452         bool needs_detach = false;
453  
454         if ( exception_tb == NULL )
455         {
456             exception_tb = MAKE_TRACEBACK( frame_function, exception_lineno );
457             needs_detach = true;
458         }
459         else if ( exception_lineno != -1 )
460         {
461             PyTracebackObject *traceback_new = MAKE_TRACEBACK( frame_function, exception_lineno );
462             traceback_new->tb_next = exception_tb;
463             exception_tb = traceback_new;
464  
465             needs_detach = true;
466         }
467  
468         if (needs_detach)
469         {
470  
471             tmp_frame_locals = PyDict_New();
472  
473  
474             detachFrame( exception_tb, tmp_frame_locals );
475         }
476     }
477  
478     popFrameStack();
479  
480 #if PYTHON_VERSION >= 340
481     frame_function->f_executing -= 1;
482 #endif
483     Py_DECREF( frame_function );
484  
485     // Return the error.
486     goto function_exception_exit;
487  
488     frame_no_exception_1:;
489  
490     tmp_return_value = Py_None; 270     tmp_return_value = Py_None;
491     Py_INCREF( tmp_return_value ); 271     Py_INCREF( tmp_return_value );
492     goto function_return_exit; 272     goto function_return_exit;
493 273
494     // Return statement must have exited already. 274     // Return statement must have exited already.
495     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 275     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
496     return NULL; 276     return NULL;
497 277
n 498 function_exception_exit: n
499     assert( exception_type );
500     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
501  
502     return NULL;
503     function_return_exit: 278     function_return_exit:
504 279
505     CHECK_OBJECT( tmp_return_value ); 280     CHECK_OBJECT( tmp_return_value );
506     assert( had_error || !ERROR_OCCURRED() ); 281     assert( had_error || !ERROR_OCCURRED() );
507     return tmp_return_value; 282     return tmp_return_value;
914         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 689         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
915         exception_tb = NULL; 690         exception_tb = NULL;
916         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 691         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
917         CHAIN_EXCEPTION( exception_value ); 692         CHAIN_EXCEPTION( exception_value );
918 693
n 919         exception_lineno = 45; n 694         exception_lineno = 47;
920         goto frame_exception_exit_1; 695         goto frame_exception_exit_1;
921     } 696     }
922 697
n 923     tmp_compare_right_1 = const_int_pos_50000; n 698     tmp_compare_right_1 = const_int_0;
924     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 ); 699     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 );
925     if ( tmp_cmp_Eq_1 == -1 ) 700     if ( tmp_cmp_Eq_1 == -1 )
926     { 701     {
927         assert( ERROR_OCCURRED() ); 702         assert( ERROR_OCCURRED() );
928 703
929         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 704         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
930 705
931 706
n 932         exception_lineno = 45; n 707         exception_lineno = 47;
933         goto frame_exception_exit_1; 708         goto frame_exception_exit_1;
934     } 709     }
935     if ( tmp_cmp_Eq_1 == 1 ) 710     if ( tmp_cmp_Eq_1 == 1 )
936     { 711     {
937         goto branch_no_1; 712         goto branch_no_1;
942     } 717     }
943     branch_yes_1:; 718     branch_yes_1:;
944     tmp_raise_type_1 = PyExc_AssertionError; 719     tmp_raise_type_1 = PyExc_AssertionError;
945     exception_type = tmp_raise_type_1; 720     exception_type = tmp_raise_type_1;
946     Py_INCREF( tmp_raise_type_1 ); 721     Py_INCREF( tmp_raise_type_1 );
t 947     exception_lineno = 45; t 722     exception_lineno = 47;
948     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 723     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
949     goto frame_exception_exit_1; 724     goto frame_exception_exit_1;
950     branch_no_1:; 725     branch_no_1:;
951     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print ); 726     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print );
952     assert( tmp_called_name_2 != NULL ); 727     assert( tmp_called_name_2 != NULL );