Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance micro optimizations #64

Open
cristianocca opened this issue Apr 3, 2015 · 1 comment
Open

Performance micro optimizations #64

cristianocca opened this issue Apr 3, 2015 · 1 comment

Comments

@cristianocca
Copy link

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.

@Melevir
Copy link
Contributor

Melevir commented Apr 3, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants