Construct GeneratorUsage

Performance Diagrams

Construct GeneratorUsage 001000000010000000200000002000000030000000300000004000000040000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)4411117088.95192307692307257.0CPython 2.718200012242.31730769230768402.1570152185943Nuitka (master)18199952395.6826923076923402.1573513448652Nuitka (develop)18200210549.0480769230769402.15590600190035Nuitka (factory)Construct GeneratorUsageTicks Construct GeneratorUsage 0010000000100000002000000020000000300000003000000040000000400000005000000050000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)5027271188.95192307692307257.0CPython 3.516699426242.31730769230768422.029398068008Nuitka (master)16749784395.6826923076923421.7818634455274Nuitka (develop)16749602549.0480769230769421.78275806607013Nuitka (factory)Construct GeneratorUsageTicks

Source Code with Construct

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    def generator():
        yield 1
        yield 2
        yield 3

    gen = generator()

    x = next(gen)
# construct_begin
    next(gen)
# construct_end

    return x

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

print("OK.")

Source Code without Construct

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    def generator():
        yield 1
        yield 2
        yield 3

    gen = generator()

    x = next(gen)
# construct_begin



    return x

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

print("OK.")

Context Diff of Source Code


Construct
Baseline
29 29
30     gen = generator() 30     gen = generator()
31 31
32     x = next(gen) 32     x = next(gen)
33 # construct_begin 33 # construct_begin
t 34     next(gen) t 34  
35 # construct_end 35  
36 36
37     return x 37     return x
38 38
39 import itertools 39 import itertools
40 for x in itertools.repeat(None, 50000): 40 for x in itertools.repeat(None, 50000):

Context Diff of Generated Code


Construct
Baseline
141     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 141     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
142     PyObject *exception_type = NULL; 142     PyObject *exception_type = NULL;
143     PyObject *exception_value = NULL; 143     PyObject *exception_value = NULL;
144     PyTracebackObject *exception_tb = NULL; 144     PyTracebackObject *exception_tb = NULL;
145     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 145     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n 146     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
147     static struct Nuitka_FrameObject *cache_frame_5a2c8ebe2db3dd40a2d21d1c1951f266 = NULL; 146     static struct Nuitka_FrameObject *cache_frame_5a2c8ebe2db3dd40a2d21d1c1951f266 = NULL;
148     PyObject *tmp_return_value = NULL; 147     PyObject *tmp_return_value = NULL;
149     PyObject *exception_keeper_type_1; 148     PyObject *exception_keeper_type_1;
150     PyObject *exception_keeper_value_1; 149     PyObject *exception_keeper_value_1;
151     PyTracebackObject *exception_keeper_tb_1; 150     PyTracebackObject *exception_keeper_tb_1;
225     } 224     }
226     assert( var_x == NULL ); 225     assert( var_x == NULL );
227     var_x = tmp_assign_source_3; 226     var_x = tmp_assign_source_3;
228 227
229     } 228     }
n 230     { n
231     PyObject *tmp_value_name_2;
232     tmp_value_name_2 = var_gen;
233  
234     if ( tmp_value_name_2 == NULL )
235     {
236  
237         exception_type = PyExc_UnboundLocalError;
238         Py_INCREF( exception_type );
239         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "gen" );
240         exception_tb = NULL;
241         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
242         CHAIN_EXCEPTION( exception_value );
243  
244         exception_lineno = 34;
245         type_description_1 = "ooo";
246         goto frame_exception_exit_1;
247     }
248  
249     tmp_unused = ITERATOR_NEXT( tmp_value_name_2 );
250     if ( tmp_unused == NULL )
251     {
252         if ( !ERROR_OCCURRED() )
253         {
254             exception_type = PyExc_StopIteration;
255             Py_INCREF( exception_type );
256             exception_value = NULL;
257             exception_tb = NULL;
258         }
259         else
260         {
261             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
262         }
263  
264  
265         type_description_1 = "ooo";
266         exception_lineno = 34;
267         goto frame_exception_exit_1;
268     }
269     Py_DECREF( tmp_unused );
270     }
271 229
272 #if 0 230 #if 0
273     RESTORE_FRAME_EXCEPTION( frame_5a2c8ebe2db3dd40a2d21d1c1951f266 ); 231     RESTORE_FRAME_EXCEPTION( frame_5a2c8ebe2db3dd40a2d21d1c1951f266 );
274 #endif 232 #endif
275 233
321     frame_no_exception_1:; 279     frame_no_exception_1:;
322 280
323     { 281     {
324     tmp_return_value = var_x; 282     tmp_return_value = var_x;
325 283
n 326     if ( tmp_return_value == NULL ) n 284     CHECK_OBJECT( tmp_return_value );
327     {
328  
329         exception_type = PyExc_UnboundLocalError;
330         Py_INCREF( exception_type );
331         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "x" );
332         exception_tb = NULL;
333         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
334         CHAIN_EXCEPTION( exception_value );
335  
336  
337  
338         goto try_except_handler_1;
339     }
340  
341     Py_INCREF( tmp_return_value ); 285     Py_INCREF( tmp_return_value );
342     goto try_return_handler_1; 286     goto try_return_handler_1;
343     } 287     }
344     // tried codes exits in all cases 288     // tried codes exits in all cases
345     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 289     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
376     exception_lineno = 0; 320     exception_lineno = 0;
377 321
378     { 322     {
379     Py_XDECREF( var_gen ); 323     Py_XDECREF( var_gen );
380     var_gen = NULL; 324     var_gen = NULL;
t 381   t
382     }
383     {
384     Py_XDECREF( var_x );
385     var_x = NULL;
386 325
387     } 326     }
388     { 327     {
389     Py_XDECREF( var_generator ); 328     Py_XDECREF( var_generator );
390     var_generator = NULL; 329     var_generator = NULL;