Construct GeneratorUsage

Performance Diagrams

Construct GeneratorUsage 001000000010000000200000002000000030000000300000004000000040000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)4411124988.95192307692307257.0CPython 2.719049462242.31730769230768397.3984986608256Nuitka (master)19050002395.6826923076923397.3954735298054Nuitka (develop)19049954549.0480769230769397.39574243034053Nuitka (factory)Construct GeneratorUsageTicks Construct GeneratorUsage 0010000000100000002000000020000000300000003000000040000000400000005000000050000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)5027304388.95192307692307257.0CPython 3.516700718242.31730769230768422.02358937786386Nuitka (master)16697314395.6826923076923422.0403216208123Nuitka (develop)16699388549.0480769230769422.0301269463484Nuitka (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
156     PyObject *tmp_assign_source_1; 156     PyObject *tmp_assign_source_1;
157     PyObject *tmp_assign_source_2; 157     PyObject *tmp_assign_source_2;
158     PyObject *tmp_assign_source_3; 158     PyObject *tmp_assign_source_3;
159     PyObject *tmp_called_name_1; 159     PyObject *tmp_called_name_1;
160     PyObject *tmp_return_value; 160     PyObject *tmp_return_value;
n 161     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; n
162     PyObject *tmp_value_name_1; 161     PyObject *tmp_value_name_1;
n 163     PyObject *tmp_value_name_2; n
164     static struct Nuitka_FrameObject *cache_frame_a3c644569d3ff606c7230b99c33386ed = NULL; 162     static struct Nuitka_FrameObject *cache_frame_a3c644569d3ff606c7230b99c33386ed = NULL;
165 163
166     struct Nuitka_FrameObject *frame_a3c644569d3ff606c7230b99c33386ed; 164     struct Nuitka_FrameObject *frame_a3c644569d3ff606c7230b99c33386ed;
167 165
168     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 166     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
227         goto frame_exception_exit_1; 225         goto frame_exception_exit_1;
228     } 226     }
229     assert( var_x == NULL ); 227     assert( var_x == NULL );
230     var_x = tmp_assign_source_3; 228     var_x = tmp_assign_source_3;
231 229
n 232     tmp_value_name_2 = var_gen; n
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 230
271 #if 0 231 #if 0
272     RESTORE_FRAME_EXCEPTION( frame_a3c644569d3ff606c7230b99c33386ed ); 232     RESTORE_FRAME_EXCEPTION( frame_a3c644569d3ff606c7230b99c33386ed );
273 #endif 233 #endif
274 234
319 279
320     frame_no_exception_1:; 280     frame_no_exception_1:;
321 281
322     tmp_return_value = var_x; 282     tmp_return_value = var_x;
323 283
n 324     if ( tmp_return_value == NULL ) n 284     CHECK_OBJECT( tmp_return_value );
325     {
326  
327         exception_type = PyExc_UnboundLocalError;
328         Py_INCREF( exception_type );
329         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "x" );
330         exception_tb = NULL;
331         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
332         CHAIN_EXCEPTION( exception_value );
333  
334  
335  
336         goto try_except_handler_1;
337     }
338  
339     Py_INCREF( tmp_return_value ); 285     Py_INCREF( tmp_return_value );
340     goto try_return_handler_1; 286     goto try_return_handler_1;
341     // tried codes exits in all cases 287     // tried codes exits in all cases
342     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 288     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
343     return NULL; 289     return NULL;
367     Py_XDECREF( var_generator ); 313     Py_XDECREF( var_generator );
368     var_generator = NULL; 314     var_generator = NULL;
369 315
370     Py_XDECREF( var_gen ); 316     Py_XDECREF( var_gen );
371     var_gen = NULL; 317     var_gen = NULL;
t 372   t
373     Py_XDECREF( var_x );
374     var_x = NULL;
375 318
376     // Re-raise. 319     // Re-raise.
377     exception_type = exception_keeper_type_1; 320     exception_type = exception_keeper_type_1;
378     exception_value = exception_keeper_value_1; 321     exception_value = exception_keeper_value_1;
379     exception_tb = exception_keeper_tb_1; 322     exception_tb = exception_keeper_tb_1;