Construct LoopSmallRange

Performance Diagrams

Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000100000000100000000110000000110000000120000000120000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)12442916088.11538461538461257.0CPython 2.752081295240.03846153846155400.68232081271725Nuitka (master)52118387391.96153846153845400.60865637709657Nuitka (develop)52081369543.8846153846154400.6821738492686Nuitka (factory)Construct LoopSmallRangeTicks Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000100000000100000000110000000110000000120000000120000000130000000130000000140000000140000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)14025958688.11538461538461257.0CPython 3.588957833240.03846153846155347.38563983811036Nuitka (master)88942909391.96153846153845347.4119335846212Nuitka (develop)88964391543.8846153846154347.37408567102256Nuitka (factory)Construct LoopSmallRangeTicks

Source Code with Construct

module_value1 = 5
module_value2 = 3

def calledRepeatedly():
    # Force frame and eliminate forward propagation (currently).
    module_value1

    # Make sure we have a local variable x anyway
    x = 2

    local_value = module_value1

# construct_begin
    for x in range(local_value, local_value+3):
        pass
# construct_end

import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

print("OK.")

Source Code without Construct

module_value1 = 5
module_value2 = 3

def calledRepeatedly():
    # Force frame and eliminate forward propagation (currently).
    module_value1

    # Make sure we have a local variable x anyway
    x = 2

    local_value = module_value1

# construct_begin




import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

print("OK.")

Context Diff of Source Code


Construct
Baseline
29     x = 2 29     x = 2
30 30
31     local_value = module_value1 31     local_value = module_value1
32 32
33 # construct_begin 33 # construct_begin
t 34     for x in range(local_value, local_value+3): t 34  
35         pass 35  
36 # construct_end 36  
37 37
38 import itertools 38 import itertools
39 for x in itertools.repeat(None, 50000): 39 for x in itertools.repeat(None, 50000):
40     calledRepeatedly() 40     calledRepeatedly()
41 41

Context Diff of Generated Code


Construct
Baseline
48 static PyObject *const_str_plain_x; 48 static PyObject *const_str_plain_x;
49 extern PyObject *const_tuple_empty; 49 extern PyObject *const_tuple_empty;
50 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352; 50 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352;
51 static PyObject *const_int_pos_5; 51 static PyObject *const_int_pos_5;
52 static PyObject *const_str_plain_repeat; 52 static PyObject *const_str_plain_repeat;
n 53 static PyObject *const_int_pos_2; n
54 static PyObject *const_tuple_none_int_pos_50000_tuple; 53 static PyObject *const_tuple_none_int_pos_50000_tuple;
55 static PyObject *const_tuple_str_plain_x_str_plain_local_value_tuple; 54 static PyObject *const_tuple_str_plain_x_str_plain_local_value_tuple;
56 extern PyObject *const_str_plain___main__; 55 extern PyObject *const_str_plain___main__;
57 extern PyObject *const_str_plain___doc__; 56 extern PyObject *const_str_plain___doc__;
58 extern PyObject *const_str_plain___cached__; 57 extern PyObject *const_str_plain___cached__;
78     const_str_angle_module = UNSTREAM_STRING_ASCII( &constant_bin[ 130 ], 8, 0 ); 77     const_str_angle_module = UNSTREAM_STRING_ASCII( &constant_bin[ 130 ], 8, 0 );
79     const_str_plain_None = UNSTREAM_STRING_ASCII( &constant_bin[ 138 ], 4, 1 ); 78     const_str_plain_None = UNSTREAM_STRING_ASCII( &constant_bin[ 138 ], 4, 1 );
80     const_str_plain_x = UNSTREAM_STRING_ASCII( &constant_bin[ 34 ], 1, 1 ); 79     const_str_plain_x = UNSTREAM_STRING_ASCII( &constant_bin[ 34 ], 1, 1 );
81     const_int_pos_5 = PyLong_FromUnsignedLong( 5ul ); 80     const_int_pos_5 = PyLong_FromUnsignedLong( 5ul );
82     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 142 ], 6, 1 ); 81     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 142 ], 6, 1 );
n 83     const_int_pos_2 = PyLong_FromUnsignedLong( 2ul ); n
84     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 82     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
85     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None ); 83     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None );
86     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 ); 84     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 );
87     const_tuple_str_plain_x_str_plain_local_value_tuple = PyTuple_New( 2 ); 85     const_tuple_str_plain_x_str_plain_local_value_tuple = PyTuple_New( 2 );
88     PyTuple_SET_ITEM( const_tuple_str_plain_x_str_plain_local_value_tuple, 0, const_str_plain_x ); Py_INCREF( const_str_plain_x ); 86     PyTuple_SET_ITEM( const_tuple_str_plain_x_str_plain_local_value_tuple, 0, const_str_plain_x ); Py_INCREF( const_str_plain_x );
127 #ifndef __NUITKA_NO_ASSERT__ 125 #ifndef __NUITKA_NO_ASSERT__
128     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 126     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
129 #endif 127 #endif
130 128
131     // Local variable declarations. 129     // Local variable declarations.
n 132     PyObject *var_x = NULL; n
133     PyObject *var_local_value = NULL; 130     PyObject *var_local_value = NULL;
n 134     PyObject *tmp_for_loop_1__for_iterator = NULL; n
135     PyObject *tmp_for_loop_1__iter_value = NULL;
136     struct Nuitka_FrameObject *frame_fa3dedcb09885e8fcd8197157f80e94e; 131     struct Nuitka_FrameObject *frame_fa3dedcb09885e8fcd8197157f80e94e;
137     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 132     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
138     PyObject *exception_type = NULL; 133     PyObject *exception_type = NULL;
139     PyObject *exception_value = NULL; 134     PyObject *exception_value = NULL;
140     PyTracebackObject *exception_tb = NULL; 135     PyTracebackObject *exception_tb = NULL;
141     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 136     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 137     static struct Nuitka_FrameObject *cache_frame_fa3dedcb09885e8fcd8197157f80e94e = NULL;
138     PyObject *tmp_return_value = NULL;
142     PyObject *exception_keeper_type_1; 139     PyObject *exception_keeper_type_1;
143     PyObject *exception_keeper_value_1; 140     PyObject *exception_keeper_value_1;
144     PyTracebackObject *exception_keeper_tb_1; 141     PyTracebackObject *exception_keeper_tb_1;
145     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 142     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 146     static struct Nuitka_FrameObject *cache_frame_fa3dedcb09885e8fcd8197157f80e94e = NULL; n
147     PyObject *tmp_return_value = NULL;
148     PyObject *exception_keeper_type_2;
149     PyObject *exception_keeper_value_2;
150     PyTracebackObject *exception_keeper_tb_2;
151     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
152 143
153     // Actual function body. 144     // Actual function body.
154     // Tried code: 145     // Tried code:
155     MAKE_OR_REUSE_FRAME( cache_frame_fa3dedcb09885e8fcd8197157f80e94e, codeobj_fa3dedcb09885e8fcd8197157f80e94e, module___main__, sizeof(void *)+sizeof(void *) ); 146     MAKE_OR_REUSE_FRAME( cache_frame_fa3dedcb09885e8fcd8197157f80e94e, codeobj_fa3dedcb09885e8fcd8197157f80e94e, module___main__, sizeof(void *)+sizeof(void *) );
156     frame_fa3dedcb09885e8fcd8197157f80e94e = cache_frame_fa3dedcb09885e8fcd8197157f80e94e; 147     frame_fa3dedcb09885e8fcd8197157f80e94e = cache_frame_fa3dedcb09885e8fcd8197157f80e94e;
180             exception_tb = NULL; 171             exception_tb = NULL;
181             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 172             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
182             CHAIN_EXCEPTION( exception_value ); 173             CHAIN_EXCEPTION( exception_value );
183 174
184             exception_lineno = 26; 175             exception_lineno = 26;
n 185             type_description_1 = "oo"; n 176             type_description_1 = "No";
186             goto frame_exception_exit_1; 177             goto frame_exception_exit_1;
187         } 178         }
188 179
189     } 180     }
190     { 181     {
191         PyObject *tmp_assign_source_1; 182         PyObject *tmp_assign_source_1;
n 192         tmp_assign_source_1 = const_int_pos_2; n
193         assert( var_x == NULL );
194         Py_INCREF( tmp_assign_source_1 );
195         var_x = tmp_assign_source_1;
196     }
197     {
198         PyObject *tmp_assign_source_2;
199         PyObject *tmp_mvar_value_2; 183         PyObject *tmp_mvar_value_2;
200         tmp_mvar_value_2 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value1 ); 184         tmp_mvar_value_2 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value1 );
201 185
202         if (unlikely( tmp_mvar_value_2 == NULL )) 186         if (unlikely( tmp_mvar_value_2 == NULL ))
203         { 187         {
213             exception_tb = NULL; 197             exception_tb = NULL;
214             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 198             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
215             CHAIN_EXCEPTION( exception_value ); 199             CHAIN_EXCEPTION( exception_value );
216 200
217             exception_lineno = 31; 201             exception_lineno = 31;
n 218             type_description_1 = "oo"; n 202             type_description_1 = "No";
219             goto frame_exception_exit_1; 203             goto frame_exception_exit_1;
220         } 204         }
221 205
n 222         tmp_assign_source_2 = tmp_mvar_value_2; n 206         tmp_assign_source_1 = tmp_mvar_value_2;
223         assert( var_local_value == NULL ); 207         assert( var_local_value == NULL );
n 224         Py_INCREF( tmp_assign_source_2 ); n 208         Py_INCREF( tmp_assign_source_1 );
225         var_local_value = tmp_assign_source_2; 209         var_local_value = tmp_assign_source_1;
226     }
227     { 210     }
228         PyObject *tmp_assign_source_3;
229         PyObject *tmp_iter_arg_1;
230         PyObject *tmp_xrange_low_1;
231         PyObject *tmp_xrange_high_1;
232         PyObject *tmp_left_name_1;
233         PyObject *tmp_right_name_1;
234         CHECK_OBJECT( var_local_value );
235         tmp_xrange_low_1 = var_local_value;
236         CHECK_OBJECT( var_local_value );
237         tmp_left_name_1 = var_local_value;
238         tmp_right_name_1 = const_int_pos_3;
239         tmp_xrange_high_1 = BINARY_OPERATION_ADD_OBJECT_LONG( tmp_left_name_1, tmp_right_name_1 );
240         if ( tmp_xrange_high_1 == NULL )
241         {
242             assert( ERROR_OCCURRED() );
243 211
n 244             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); n 212 #if 0
213     RESTORE_FRAME_EXCEPTION( frame_fa3dedcb09885e8fcd8197157f80e94e );
214 #endif
245 215
n n 216     // Put the previous frame back on top.
217     popFrameStack();
246 218
n 247             exception_lineno = 34; n 219     goto frame_no_exception_1;
248             type_description_1 = "oo"; 220  
249             goto frame_exception_exit_1; 221     frame_exception_exit_1:;
250         }
251         tmp_iter_arg_1 = BUILTIN_XRANGE2( tmp_xrange_low_1, tmp_xrange_high_1 );
252         Py_DECREF( tmp_xrange_high_1 );
253         if ( tmp_iter_arg_1 == NULL )
254         {
255             assert( ERROR_OCCURRED() );
256 222
n 257             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); n 223 #if 0
224     RESTORE_FRAME_EXCEPTION( frame_fa3dedcb09885e8fcd8197157f80e94e );
225 #endif
258 226
n 259   n 227     if ( exception_tb == NULL )
260             exception_lineno = 34;
261             type_description_1 = "oo";
262             goto frame_exception_exit_1;
263         }
264         tmp_assign_source_3 = MAKE_ITERATOR( tmp_iter_arg_1 );
265         Py_DECREF( tmp_iter_arg_1 );
266         if ( tmp_assign_source_3 == NULL )
267         {
268             assert( ERROR_OCCURRED() );
269  
270             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
271  
272  
273             exception_lineno = 34;
274             type_description_1 = "oo";
275             goto frame_exception_exit_1;
276         }
277         assert( tmp_for_loop_1__for_iterator == NULL );
278         tmp_for_loop_1__for_iterator = tmp_assign_source_3;
279     } 228     {
280     // Tried code: 229         exception_tb = MAKE_TRACEBACK( frame_fa3dedcb09885e8fcd8197157f80e94e, exception_lineno );
281     loop_start_1:;
282     { 230     }
283         PyObject *tmp_next_source_1; 231     else if ( exception_tb->tb_frame != &frame_fa3dedcb09885e8fcd8197157f80e94e->m_frame )
284         PyObject *tmp_assign_source_4;
285         CHECK_OBJECT( tmp_for_loop_1__for_iterator );
286         tmp_next_source_1 = tmp_for_loop_1__for_iterator;
287         tmp_assign_source_4 = ITERATOR_NEXT( tmp_next_source_1 );
288         if ( tmp_assign_source_4 == NULL )
289         {
290             if ( CHECK_AND_CLEAR_STOP_ITERATION_OCCURRED() )
291             {
292  
293                 goto loop_end_1;
294             }
295             else
296             {
297  
298                 FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
299                 type_description_1 = "oo";
300                 exception_lineno = 34;
301                 goto try_except_handler_2;
302             }
303         }
304  
305         {
306             PyObject *old = tmp_for_loop_1__iter_value;
307             tmp_for_loop_1__iter_value = tmp_assign_source_4;
308             Py_XDECREF( old );
309         }
310  
311     } 232     {
233         exception_tb = ADD_TRACEBACK( exception_tb, frame_fa3dedcb09885e8fcd8197157f80e94e, exception_lineno );
312     { 234     }
313         PyObject *tmp_assign_source_5;
314         CHECK_OBJECT( tmp_for_loop_1__iter_value );
315         tmp_assign_source_5 = tmp_for_loop_1__iter_value;
316         {
317             PyObject *old = var_x;
318             assert( old != NULL );
319             var_x = tmp_assign_source_5;
320             Py_INCREF( var_x );
321             Py_DECREF( old );
322         }
323 235
n 324     } n 236     // Attachs locals to frame if any.
325     if ( CONSIDER_THREADING() == false ) 237     Nuitka_Frame_AttachLocals(
326     { 238         (struct Nuitka_FrameObject *)frame_fa3dedcb09885e8fcd8197157f80e94e,
327         assert( ERROR_OCCURRED() );
328  
329         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
330  
331  
332         exception_lineno = 34;
333         type_description_1 = "oo"; 239         type_description_1,
240         NULL,
241         var_local_value
242     );
243  
244  
245     // Release cached frame.
246     if ( frame_fa3dedcb09885e8fcd8197157f80e94e == cache_frame_fa3dedcb09885e8fcd8197157f80e94e )
247     {
248         Py_DECREF( frame_fa3dedcb09885e8fcd8197157f80e94e );
249     }
250     cache_frame_fa3dedcb09885e8fcd8197157f80e94e = NULL;
251  
252     assertFrameObject( frame_fa3dedcb09885e8fcd8197157f80e94e );
253  
254     // Put the previous frame back on top.
255     popFrameStack();
256  
257     // Return the error.
334         goto try_except_handler_2; 258     goto try_except_handler_1;
335     } 259  
336     goto loop_start_1; 260     frame_no_exception_1:;
337     loop_end_1:; 261     tmp_return_value = Py_None;
262     Py_INCREF( tmp_return_value );
338     goto try_end_1; 263     goto try_return_handler_1;
264     // tried codes exits in all cases
265     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
266     return NULL;
267     // Return handler code:
268     try_return_handler_1:;
269     CHECK_OBJECT( (PyObject *)var_local_value );
270     Py_DECREF( var_local_value );
271     var_local_value = NULL;
272  
273     goto function_return_exit;
339     // Exception handler code: 274     // Exception handler code:
n 340     try_except_handler_2:; n 275     try_except_handler_1:;
341     exception_keeper_type_1 = exception_type; 276     exception_keeper_type_1 = exception_type;
342     exception_keeper_value_1 = exception_value; 277     exception_keeper_value_1 = exception_value;
343     exception_keeper_tb_1 = exception_tb; 278     exception_keeper_tb_1 = exception_tb;
344     exception_keeper_lineno_1 = exception_lineno; 279     exception_keeper_lineno_1 = exception_lineno;
345     exception_type = NULL; 280     exception_type = NULL;
346     exception_value = NULL; 281     exception_value = NULL;
347     exception_tb = NULL; 282     exception_tb = NULL;
348     exception_lineno = 0; 283     exception_lineno = 0;
349 284
n 350     Py_XDECREF( tmp_for_loop_1__iter_value ); n
351     tmp_for_loop_1__iter_value = NULL;
352  
353     CHECK_OBJECT( (PyObject *)tmp_for_loop_1__for_iterator );
354     Py_DECREF( tmp_for_loop_1__for_iterator );
355     tmp_for_loop_1__for_iterator = NULL;
356  
357     // Re-raise. 285     // Re-raise.
358     exception_type = exception_keeper_type_1; 286     exception_type = exception_keeper_type_1;
359     exception_value = exception_keeper_value_1; 287     exception_value = exception_keeper_value_1;
360     exception_tb = exception_keeper_tb_1; 288     exception_tb = exception_keeper_tb_1;
361     exception_lineno = exception_keeper_lineno_1; 289     exception_lineno = exception_keeper_lineno_1;
t 362   t
363     goto frame_exception_exit_1;
364     // End of try:
365     try_end_1:;
366  
367 #if 0
368     RESTORE_FRAME_EXCEPTION( frame_fa3dedcb09885e8fcd8197157f80e94e );
369 #endif
370  
371     // Put the previous frame back on top.
372     popFrameStack();
373  
374     goto frame_no_exception_1;
375  
376     frame_exception_exit_1:;
377  
378 #if 0
379     RESTORE_FRAME_EXCEPTION( frame_fa3dedcb09885e8fcd8197157f80e94e );
380 #endif
381  
382     if ( exception_tb == NULL )
383     {
384         exception_tb = MAKE_TRACEBACK( frame_fa3dedcb09885e8fcd8197157f80e94e, exception_lineno );
385     }
386     else if ( exception_tb->tb_frame != &frame_fa3dedcb09885e8fcd8197157f80e94e->m_frame )
387     {
388         exception_tb = ADD_TRACEBACK( exception_tb, frame_fa3dedcb09885e8fcd8197157f80e94e, exception_lineno );
389     }
390  
391     // Attachs locals to frame if any.
392     Nuitka_Frame_AttachLocals(
393         (struct Nuitka_FrameObject *)frame_fa3dedcb09885e8fcd8197157f80e94e,
394         type_description_1,
395         var_x,
396         var_local_value
397     );
398  
399  
400     // Release cached frame.
401     if ( frame_fa3dedcb09885e8fcd8197157f80e94e == cache_frame_fa3dedcb09885e8fcd8197157f80e94e )
402     {
403         Py_DECREF( frame_fa3dedcb09885e8fcd8197157f80e94e );
404     }
405     cache_frame_fa3dedcb09885e8fcd8197157f80e94e = NULL;
406  
407     assertFrameObject( frame_fa3dedcb09885e8fcd8197157f80e94e );
408  
409     // Put the previous frame back on top.
410     popFrameStack();
411  
412     // Return the error.
413     goto try_except_handler_1;
414  
415     frame_no_exception_1:;
416     Py_XDECREF( tmp_for_loop_1__iter_value );
417     tmp_for_loop_1__iter_value = NULL;
418  
419     CHECK_OBJECT( (PyObject *)tmp_for_loop_1__for_iterator );
420     Py_DECREF( tmp_for_loop_1__for_iterator );
421     tmp_for_loop_1__for_iterator = NULL;
422  
423     tmp_return_value = Py_None;
424     Py_INCREF( tmp_return_value );
425     goto try_return_handler_1;
426     // tried codes exits in all cases
427     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
428     return NULL;
429     // Return handler code:
430     try_return_handler_1:;
431     CHECK_OBJECT( (PyObject *)var_x );
432     Py_DECREF( var_x );
433     var_x = NULL;
434  
435     CHECK_OBJECT( (PyObject *)var_local_value );
436     Py_DECREF( var_local_value );
437     var_local_value = NULL;
438  
439     goto function_return_exit;
440     // Exception handler code:
441     try_except_handler_1:;
442     exception_keeper_type_2 = exception_type;
443     exception_keeper_value_2 = exception_value;
444     exception_keeper_tb_2 = exception_tb;
445     exception_keeper_lineno_2 = exception_lineno;
446     exception_type = NULL;
447     exception_value = NULL;
448     exception_tb = NULL;
449     exception_lineno = 0;
450  
451     Py_XDECREF( var_x );
452     var_x = NULL;
453  
454     Py_XDECREF( var_local_value );
455     var_local_value = NULL;
456  
457     // Re-raise.
458     exception_type = exception_keeper_type_2;
459     exception_value = exception_keeper_value_2;
460     exception_tb = exception_keeper_tb_2;
461     exception_lineno = exception_keeper_lineno_2;
462 290
463     goto function_exception_exit; 291     goto function_exception_exit;
464     // End of try: 292     // End of try:
465 293
466     // Return statement must have exited already. 294     // Return statement must have exited already.