Construct FunctionRaise

Performance Diagrams

Construct FunctionRaise 00100000000100000000200000000200000000300000000300000000400000000400000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)43325352172.9230769230769257.0CPython 2.7196178697194.46153846153845392.2206813695684Nuitka (historic)193985250316.0393.4717606401705Nuitka (master)193984553437.53846153846143393.4721581889837Nuitka (develop)180948574559.0769230769231400.9075067973175Nuitka (factory)Construct FunctionRaiseTicks Construct FunctionRaise 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)17517864172.9230769230769257.0CPython 3.50194.46153846153845504.11538461538464Nuitka (historic)151179832316.0290.85386986959304Nuitka (master)151284548437.53846153846143290.70615246256403Nuitka (develop)114783740559.0769230769231342.195941150286Nuitka (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
247 #ifndef __NUITKA_NO_ASSERT__ 247 #ifndef __NUITKA_NO_ASSERT__
248     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 248     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
249 #endif 249 #endif
250 250
251     // Local variable declarations. 251     // Local variable declarations.
n 252     PyObject *exception_type = NULL, *exception_value = NULL; n
253     PyTracebackObject *exception_tb = NULL;
254     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
255     PyObject *exception_keeper_type_1;
256     PyObject *exception_keeper_value_1;
257     PyTracebackObject *exception_keeper_tb_1;
258     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
259     PyObject *exception_keeper_type_2;
260     PyObject *exception_keeper_value_2;
261     PyTracebackObject *exception_keeper_tb_2;
262     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
263     PyObject *exception_preserved_type_1;
264     PyObject *exception_preserved_value_1;
265     PyTracebackObject *exception_preserved_tb_1;
266     PyObject *tmp_called_name_1;
267     PyObject *tmp_compare_left_1;
268     PyObject *tmp_compare_right_1;
269     int tmp_exc_match_exception_match_1;
270     PyObject *tmp_return_value; 252     PyObject *tmp_return_value;
n 271     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
272     static struct Nuitka_FrameObject *cache_frame_function = NULL;
273  
274     struct Nuitka_FrameObject *frame_function;
275  
276     tmp_return_value = NULL; 253     tmp_return_value = NULL;
277 254
278     // Actual function code. 255     // Actual function code.
n 279     MAKE_OR_REUSE_FRAME( cache_frame_function, codeobj_3470847bfa123148b2425bfa86031230, module___main__, 0 ); n
280     frame_function = cache_frame_function;
281  
282     // Push the new frame as the currently active one.
283     pushFrameStack( frame_function );
284  
285     // Mark the frame object as in use, ref count 1 will be up for reuse.
286     assert( Py_REFCNT( frame_function ) == 2 ); // Frame stack
287  
288     // Framed code:
289     // Tried code:
290     tmp_called_name_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_raisy );
291  
292     if (unlikely( tmp_called_name_1 == NULL ))
293     {
294         tmp_called_name_1 = GET_STRING_DICT_VALUE( dict_builtin, (Nuitka_StringObject *)const_str_plain_raisy );
295     }
296  
297     if ( tmp_called_name_1 == NULL )
298     {
299  
300         exception_type = PyExc_NameError;
301         Py_INCREF( exception_type );
302         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "raisy" );
303         exception_tb = NULL;
304         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
305         CHAIN_EXCEPTION( exception_value );
306  
307         exception_lineno = 34;
308  
309         goto try_except_handler_1;
310     }
311  
312     frame_function->m_frame.f_lineno = 34;
313     tmp_unused = CALL_FUNCTION_NO_ARGS( tmp_called_name_1 );
314     if ( tmp_unused == NULL )
315     {
316         assert( ERROR_OCCURRED() );
317  
318         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
319  
320  
321         exception_lineno = 34;
322  
323         goto try_except_handler_1;
324     }
325     Py_DECREF( tmp_unused );
326     goto try_end_1;
327     // Exception handler code:
328     try_except_handler_1:;
329     exception_keeper_type_1 = exception_type;
330     exception_keeper_value_1 = exception_value;
331     exception_keeper_tb_1 = exception_tb;
332     exception_keeper_lineno_1 = exception_lineno;
333     exception_type = NULL;
334     exception_value = NULL;
335     exception_tb = NULL;
336     exception_lineno = -1;
337  
338     // Preserve existing published exception.
339     exception_preserved_type_1 = PyThreadState_GET()->exc_type;
340     Py_XINCREF( exception_preserved_type_1 );
341     exception_preserved_value_1 = PyThreadState_GET()->exc_value;
342     Py_XINCREF( exception_preserved_value_1 );
343     exception_preserved_tb_1 = (PyTracebackObject *)PyThreadState_GET()->exc_traceback;
344     Py_XINCREF( exception_preserved_tb_1 );
345  
346     if ( exception_keeper_tb_1 == NULL )
347     {
348         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_function, exception_keeper_lineno_1 );
349     }
350     else if ( exception_keeper_lineno_1 != -1 )
351     {
352         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_function, exception_keeper_lineno_1 );
353     }
354  
355     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
356     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
357     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
358     // Tried code:
359     tmp_compare_left_1 = PyThreadState_GET()->exc_type;
360     tmp_compare_right_1 = PyExc_TypeError;
361     tmp_exc_match_exception_match_1 = EXCEPTION_MATCH_BOOL( tmp_compare_left_1, tmp_compare_right_1 );
362     if ( tmp_exc_match_exception_match_1 == -1 )
363     {
364         assert( ERROR_OCCURRED() );
365  
366         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
367  
368  
369         exception_lineno = 35;
370  
371         goto try_except_handler_2;
372     }
373     if ( tmp_exc_match_exception_match_1 == 1 )
374     {
375         goto branch_no_1;
376     }
377     else
378     {
379         goto branch_yes_1;
380     }
381     branch_yes_1:;
382     RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
383     if (exception_tb && exception_tb->tb_frame == &frame_function->m_frame) frame_function->m_frame.f_lineno = exception_tb->tb_lineno;
384  
385     goto try_except_handler_2;
386     branch_no_1:;
387     goto try_end_2;
388     // Exception handler code:
389     try_except_handler_2:;
390     exception_keeper_type_2 = exception_type;
391     exception_keeper_value_2 = exception_value;
392     exception_keeper_tb_2 = exception_tb;
393     exception_keeper_lineno_2 = exception_lineno;
394     exception_type = NULL;
395     exception_value = NULL;
396     exception_tb = NULL;
397     exception_lineno = -1;
398  
399     // Restore previous exception.
400     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
401     // Re-raise.
402     exception_type = exception_keeper_type_2;
403     exception_value = exception_keeper_value_2;
404     exception_tb = exception_keeper_tb_2;
405     exception_lineno = exception_keeper_lineno_2;
406  
407     goto frame_exception_exit_1;
408     // End of try:
409     try_end_2:;
410     // Restore previous exception.
411     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
412     goto try_end_1;
413     // exception handler codes exits in all cases
414     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
415     return NULL;
416     // End of try:
417     try_end_1:;
418  
419 #if 1
420     RESTORE_FRAME_EXCEPTION( frame_function );
421 #endif
422  
423     // Put the previous frame back on top.
424     popFrameStack();
425  
426     goto frame_no_exception_1;
427  
428     frame_exception_exit_1:;
429  
430 #if 1
431     RESTORE_FRAME_EXCEPTION( frame_function );
432 #endif
433  
434     if ( exception_tb == NULL )
435     {
436         exception_tb = MAKE_TRACEBACK( frame_function, exception_lineno );
437     }
438     else if ( exception_tb->tb_frame != &frame_function->m_frame )
439     {
440         exception_tb = ADD_TRACEBACK( exception_tb, frame_function, exception_lineno );
441     }
442  
443     Nuitka_Frame_AttachLocals( (struct Nuitka_FrameObject *)frame_function, ""  );
444  
445     // Release cached frame.
446     if ( frame_function == cache_frame_function )
447     {
448         Py_DECREF( frame_function );
449     }
450     cache_frame_function = NULL;
451  
452     assertFrameObject( frame_function );
453  
454  
455     // Put the previous frame back on top.
456     popFrameStack();
457  
458     // Return the error.
459     goto function_exception_exit;
460  
461     frame_no_exception_1:;
462  
463     tmp_return_value = Py_None; 256     tmp_return_value = Py_None;
464     Py_INCREF( tmp_return_value ); 257     Py_INCREF( tmp_return_value );
465     goto function_return_exit; 258     goto function_return_exit;
466 259
467     // Return statement must have exited already. 260     // Return statement must have exited already.
468     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly ); 261     NUITKA_CANNOT_GET_HERE( __main__$$$function_2_calledRepeatedly );
469     return NULL; 262     return NULL;
470 263
n 471 function_exception_exit: n
472     assert( exception_type );
473     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
474  
475     return NULL;
476     function_return_exit: 264     function_return_exit:
477 265
478     CHECK_OBJECT( tmp_return_value ); 266     CHECK_OBJECT( tmp_return_value );
479     assert( had_error || !ERROR_OCCURRED() ); 267     assert( had_error || !ERROR_OCCURRED() );
480     return tmp_return_value; 268     return tmp_return_value;
890         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" ); 678         exception_value = PyUnicode_FromFormat( "name '%s' is not defined", "count" );
891         exception_tb = NULL; 679         exception_tb = NULL;
892         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 680         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
893         CHAIN_EXCEPTION( exception_value ); 681         CHAIN_EXCEPTION( exception_value );
894 682
n 895         exception_lineno = 45; n 683         exception_lineno = 47;
896 684
897         goto frame_exception_exit_1; 685         goto frame_exception_exit_1;
898     } 686     }
899 687
n 900     tmp_compare_right_1 = const_int_pos_50000; n 688     tmp_compare_right_1 = const_int_0;
901     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 ); 689     tmp_cmp_Eq_1 = RICH_COMPARE_BOOL_EQ_NORECURSE( tmp_compare_left_1, tmp_compare_right_1 );
902     if ( tmp_cmp_Eq_1 == -1 ) 690     if ( tmp_cmp_Eq_1 == -1 )
903     { 691     {
904         assert( ERROR_OCCURRED() ); 692         assert( ERROR_OCCURRED() );
905 693
906         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); 694         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
907 695
908 696
n 909         exception_lineno = 45; n 697         exception_lineno = 47;
910 698
911         goto frame_exception_exit_1; 699         goto frame_exception_exit_1;
912     } 700     }
913     if ( tmp_cmp_Eq_1 == 1 ) 701     if ( tmp_cmp_Eq_1 == 1 )
914     { 702     {
920     } 708     }
921     branch_yes_1:; 709     branch_yes_1:;
922     tmp_raise_type_1 = PyExc_AssertionError; 710     tmp_raise_type_1 = PyExc_AssertionError;
923     exception_type = tmp_raise_type_1; 711     exception_type = tmp_raise_type_1;
924     Py_INCREF( tmp_raise_type_1 ); 712     Py_INCREF( tmp_raise_type_1 );
t 925     exception_lineno = 45; t 713     exception_lineno = 47;
926     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb ); 714     RAISE_EXCEPTION_WITH_TYPE( &exception_type, &exception_value, &exception_tb );
927 715
928     goto frame_exception_exit_1; 716     goto frame_exception_exit_1;
929     branch_no_1:; 717     branch_no_1:;
930     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print ); 718     tmp_called_name_2 = LOOKUP_BUILTIN( const_str_plain_print );