Construct GeneratorUsage

Performance Diagrams

Construct GeneratorUsage 001000000010000000200000002000000030000000300000004000000040000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)4324355173.61538461538461257.0CPython 2.70196.30769230769232504.11538461538464Nuitka (historic)17700158319.0000000000001402.96778570698143Nuitka (master)17698958441.69230769230774402.9746431101013Nuitka (develop)17750850564.3846153846155402.6781061411909Nuitka (factory)Construct GeneratorUsageTicks Construct GeneratorUsage 0010000000100000002000000020000000300000003000000040000000400000005000000050000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)5037516173.61538461538461257.0CPython 3.50196.30769230769232504.11538461538464Nuitka (historic)16700143319.0000000000001422.1928224110291Nuitka (master)16700095441.69230769230774422.19305787505994Nuitka (develop)16550013564.3846153846155422.9292852223799Nuitka (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

for x in xrange(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

for x in xrange(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 for x in xrange(50000): 39 for x in xrange(50000):
40     calledRepeatedly() 40     calledRepeatedly()

Context Diff of Generated Code


Construct
Baseline
143     PyObject *tmp_assign_source_1; 143     PyObject *tmp_assign_source_1;
144     PyObject *tmp_assign_source_2; 144     PyObject *tmp_assign_source_2;
145     PyObject *tmp_assign_source_3; 145     PyObject *tmp_assign_source_3;
146     PyObject *tmp_called_name_1; 146     PyObject *tmp_called_name_1;
147     PyObject *tmp_return_value; 147     PyObject *tmp_return_value;
n 148     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
149     PyObject *tmp_value_name_1; 148     PyObject *tmp_value_name_1;
n 150     PyObject *tmp_value_name_2; n
151     static struct Nuitka_FrameObject *cache_frame_function = NULL; 149     static struct Nuitka_FrameObject *cache_frame_function = NULL;
152 150
153     struct Nuitka_FrameObject *frame_function; 151     struct Nuitka_FrameObject *frame_function;
154 152
155     char const *type_description; 153     char const *type_description;
212         goto frame_exception_exit_1; 210         goto frame_exception_exit_1;
213     } 211     }
214     assert( var_x == NULL ); 212     assert( var_x == NULL );
215     var_x = tmp_assign_source_3; 213     var_x = tmp_assign_source_3;
216 214
n 217     tmp_value_name_2 = var_gen; n
218  
219     if ( tmp_value_name_2 == NULL )
220     {
221  
222         exception_type = PyExc_UnboundLocalError;
223         Py_INCREF( exception_type );
224         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "gen" );
225         exception_tb = NULL;
226         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
227         CHAIN_EXCEPTION( exception_value );
228  
229         exception_lineno = 34;
230         type_description = "ooo";
231         goto frame_exception_exit_1;
232     }
233  
234     tmp_unused = ITERATOR_NEXT( tmp_value_name_2 );
235     if ( tmp_unused == NULL )
236     {
237         if ( !ERROR_OCCURRED() )
238         {
239             exception_type = PyExc_StopIteration;
240             Py_INCREF( exception_type );
241             exception_value = NULL;
242             exception_tb = NULL;
243         }
244         else
245         {
246             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
247         }
248  
249  
250         type_description = "ooo";
251         exception_lineno = 34;
252         goto frame_exception_exit_1;
253     }
254     Py_DECREF( tmp_unused );
255 215
256 #if 0 216 #if 0
257     RESTORE_FRAME_EXCEPTION( frame_function ); 217     RESTORE_FRAME_EXCEPTION( frame_function );
258 #endif 218 #endif
259 219
296     goto try_except_handler_1; 256     goto try_except_handler_1;
297 257
298     frame_no_exception_1:; 258     frame_no_exception_1:;
299 259
300     tmp_return_value = var_x; 260     tmp_return_value = var_x;
n 301   n
302     if ( tmp_return_value == NULL )
303     {
304  
305         exception_type = PyExc_UnboundLocalError;
306         Py_INCREF( exception_type );
307         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "x" );
308         exception_tb = NULL;
309         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
310         CHAIN_EXCEPTION( exception_value );
311  
312  
313  
314         goto try_except_handler_1;
315     }
316 261
317     Py_INCREF( tmp_return_value ); 262     Py_INCREF( tmp_return_value );
318     goto try_return_handler_1; 263     goto try_return_handler_1;
319     // tried codes exits in all cases 264     // tried codes exits in all cases
320     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 265     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
345     Py_XDECREF( var_generator ); 290     Py_XDECREF( var_generator );
346     var_generator = NULL; 291     var_generator = NULL;
347 292
348     Py_XDECREF( var_gen ); 293     Py_XDECREF( var_gen );
349     var_gen = NULL; 294     var_gen = NULL;
t 350   t
351     Py_XDECREF( var_x );
352     var_x = NULL;
353 295
354     // Re-raise. 296     // Re-raise.
355     exception_type = exception_keeper_type_1; 297     exception_type = exception_keeper_type_1;
356     exception_value = exception_keeper_value_1; 298     exception_value = exception_keeper_value_1;
357     exception_tb = exception_keeper_tb_1; 299     exception_tb = exception_keeper_tb_1;