Performance issues using multiple generator layers in Python?

Are there any performance considerations for using multiple generators connected together, and not just with one generator.

For example:

def A(self, items):
    for item in self.AB(items):
        if object.A():
            yield item

def AB(self, items):
    for object in self.ABC(objects):
        if object.A() or object.B():
            yield object

def ABC(self, objects):
    for object in objects:
        if object.A() or object.B() or object.C():
            yield object

Clearly, the call A(objects)will go through three different generators, but in many situations it makes code reuse better if there are different generators to handle different filtering. Can anyone point out that there is a significant impact on performance using this technique?

+3
source share
1 answer

, A self.AB, .

, , , , , . , , , .

+2

Source: https://habr.com/ru/post/1706575/


All Articles