Construct LoopSmallRange

Performance Diagrams

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