"is_contained()" indeed accounts for most of the run time, but "gene_to_legal_range()" is also much slower than I would expect.
Updated benchmarks (tested again with the original posted code):
- Both subroutines executed: ~64 seconds
- Only "gene_to_legal_range()" is executed: ~15 seconds
- Only "gene_to_legal_range()" is executed but its body replaced with just a return: ~6.1 seconds
- none is executed: ~4.5 seconds
So "gene_to_legal_range()", which is quite simple, triples the run time (15 vs 4.5). Also just calling this subroutine, even if it does nothing (just a return) adds some significant time (6.1 vs 4.5).
In the final program I will have ~1000 iterations (instead of 50) so these differences do matter.
To conclude, I agree that "is_contained()" consumes more time, but I suggest that we first assert that the first, much simpler function is "optimal" Since I'm new to perl optimization, this might also help me know what to expect, what is considered OK (e.g. such an overhead for a subroutine call?) and what is not.
UPDATE: and as for sort, again, I removed it completely. Got ~60 seconds (instead of ~64). But I again suggest we first "clear" with the first, simpler sub.
In reply to Re^6: Some code optimization
by roibrodo
in thread Some code optimization
by roibrodo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |