Class optimization at runtime

brianc at temple.edu brianc at temple.edu
Mon Aug 2 22:41:58 CEST 2004


I would like to optimize my classes at run time. The question
is where to put my "if" statement. 
-Inside __main__?
if option:
    class Foo:
        def __init__:
            #do stuff
else:
    class Foo:
        def __init__:
            #do other stuff
-Inside class definition?
class Foo:
    if option:
        def __init__:
            #do stuff
    else:
        def __init__:
            #do other stuff
-Inside each method definition?
class Foo:
    def __init__:
        if option:
            #do stuff
        else:
            #do other stuff

Class instances will be created millions of times and the
method's on them called even more so whatever brings the most
speed will be used. I fear that the more readable way to do it
is also the slowest. 

Thanks in advance,
-Brian



More information about the Python-list mailing list