do not compute the division several times.
That's debatable. The trade-off is, arivu calculates the division only a second time if it's actually smaller than the previous minimum value. You store the result in a variable *all the time*. Your benchmark is biased in your favour because Perl actually keeps the variable skeleton around for each iteration of the benchmark. You're also using split instead of pattern with backreferences. If both "arivu" and "choroba" use split, the smallest ratio is in the beginning of the list, and the benchmark uses strings instead of subs (to avoid costs being amortized over runs), arivu's solution is actually marginally faster. (On my machine, and by 5% +/- 6%).
So, what can we conclude?
- Benchmarking is harder than you think.
- The real gain is in the split vs backref pattern.
- Doing a "low cost" operation all the time isn't always faster than doing a slightly "less lower cost" sometimes.