You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code can certain use some very small performance changes, which after summing up all changes it should improve performance slightly.
I'm talking about thinks like, use correct structures, more pytonic code, etc..
For example:
Using a list for just TWO elements: cuts = [rand_randint(1, len(gMom)-1), rand_randint(1, len(gMom)-1)]
Might be better just having two separate vars or a tuple.
This is in Crossovers
return True if rand_random() <= p else False in Util.py. Like really? Could be just return rand_random() <= p
Do not re calculate lengths every time, if you are planning on using len(something) many times, assign it to a variable first and then use it.
Define functions that are used in big loops, as a local variable, since doing var1.var2.somefunc on a loop is expensive due to look ups every time.
The text was updated successfully, but these errors were encountered:
Most of optimisations more about code style, not performance.
For example, var1.var2.somefunc takes constant time, return True if rand_random() <= p else False doesn't affect perfomance also, cuts = [rand_randint(1, len(gMom)-1), rand_randint(1, len(gMom)-1)] will have effect only if it's created > 1M times or so. Same thing about len(something).
Don't get me wrong, these changes are nice idea, but readability should not suffer because something might work 1E-4 sec faster is some cases.
The code can certain use some very small performance changes, which after summing up all changes it should improve performance slightly.
I'm talking about thinks like, use correct structures, more pytonic code, etc..
For example:
Using a list for just TWO elements: cuts = [rand_randint(1, len(gMom)-1), rand_randint(1, len(gMom)-1)]
Might be better just having two separate vars or a tuple.
This is in Crossovers
return True if rand_random() <= p else False in Util.py. Like really? Could be just return rand_random() <= p
Do not re calculate lengths every time, if you are planning on using len(something) many times, assign it to a variable first and then use it.
Define functions that are used in big loops, as a local variable, since doing var1.var2.somefunc on a loop is expensive due to look ups every time.
The text was updated successfully, but these errors were encountered: