I'm not sure how to improve the performance, since reading this code is pretty difficult. It's not the worst I've seen, but it could still be improved. For starters, your `main` function is *way* too long. For readability, it's generally recognized that [a function should be no longer than what can take up one screen, or one printed page](http://programmers.stackexchange.com/a/27976/70034). This helps with readability and maintainability. I like to try to keep mine below about 70 lines. You're also using a `goto`, and while this is hotly debated, I'd recommend against using it. Here's how you might structure this: class Pieces { [member variables] }; int reproduction(int geneA, int geneB, int j) { [...] } int aleADN() { [...] } string* readFile(string filename){ [..] } int evaluate(Pieces * pieces) { int result = 1; [...] return result; } double selection(Pieces* pieces) { [...] return fitness; } void mate(pieces) { [...] } void evolution(Pieces* pieces) { int done = 1; do { [...] done = evaluate(pieces); fitness = selection(pieces); // mating leads to reproduction mate(pieces, fitness); mutate(); } while (done != 0); } int main() { string* file_lines = readFile(filename); bool done = FALSE; checkIntegrity(); initialization(); Pieces * pieces = new Pieces[POPULATION]; evolution(pieces); // solution printout here }