Construct GeneratorUsage

Performance Diagrams

Construct GeneratorUsage 001000000010000000200000002000000030000000300000004000000040000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)4204317788.95192307692307257.0CPython 2.717749447242.31730769230768399.79021855775335Nuitka (master)17799427395.6826923076923399.4964532477941Nuitka (develop)17799415549.0480769230769399.49652377968124Nuitka (factory)Construct GeneratorUsageTicks Construct GeneratorUsage 0010000000100000002000000020000000300000003000000040000000400000005000000050000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)5037512888.95192307692307257.0CPython 3.516579991242.31730769230768422.78217484399477Nuitka (master)16550136395.6826923076923422.92862866159487Nuitka (develop)16549978549.0480769230769422.929403731204Nuitka (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_a6e5c4bcb3f0c7bbb1a7131e92031d4d = NULL; 162     static struct Nuitka_FrameObject *cache_frame_a6e5c4bcb3f0c7bbb1a7131e92031d4d = NULL;
165 163
166     struct Nuitka_FrameObject *frame_a6e5c4bcb3f0c7bbb1a7131e92031d4d; 164     struct Nuitka_FrameObject *frame_a6e5c4bcb3f0c7bbb1a7131e92031d4d;
167 165
168     char const *type_description; 166     char const *type_description;
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 = "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 = "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_a6e5c4bcb3f0c7bbb1a7131e92031d4d ); 232     RESTORE_FRAME_EXCEPTION( frame_a6e5c4bcb3f0c7bbb1a7131e92031d4d );
273 #endif 233 #endif
274 234
312 272
313     frame_no_exception_1:; 273     frame_no_exception_1:;
314 274
315     tmp_return_value = var_x; 275     tmp_return_value = var_x;
316 276
n 317     if ( tmp_return_value == NULL ) n 277     CHECK_OBJECT( tmp_return_value );
318     {
319  
320         exception_type = PyExc_UnboundLocalError;
321         Py_INCREF( exception_type );
322         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "x" );
323         exception_tb = NULL;
324         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
325         CHAIN_EXCEPTION( exception_value );
326  
327  
328  
329         goto try_except_handler_1;
330     }
331  
332     Py_INCREF( tmp_return_value ); 278     Py_INCREF( tmp_return_value );
333     goto try_return_handler_1; 279     goto try_return_handler_1;
334     // tried codes exits in all cases 280     // tried codes exits in all cases
335     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 281     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
336     return NULL; 282     return NULL;
360     Py_XDECREF( var_generator ); 306     Py_XDECREF( var_generator );
361     var_generator = NULL; 307     var_generator = NULL;
362 308
363     Py_XDECREF( var_gen ); 309     Py_XDECREF( var_gen );
364     var_gen = NULL; 310     var_gen = NULL;
t 365   t
366     Py_XDECREF( var_x );
367     var_x = NULL;
368 311
369     // Re-raise. 312     // Re-raise.
370     exception_type = exception_keeper_type_1; 313     exception_type = exception_keeper_type_1;
371     exception_value = exception_keeper_value_1; 314     exception_value = exception_keeper_value_1;
372     exception_tb = exception_keeper_tb_1; 315     exception_tb = exception_keeper_tb_1;