Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: run time of math problem



On 2021-03-19 4:52 p.m., Oliver Kiddle wrote:

If you want to optimise for speed, avoid string conversions and do, e.g.
   (( divided = sum * (1.0 / level) ))
Thanks, that's easy to miss but it makes sense.  One of those invisible things.  Doing it that way throughout is fully 3X faster.  Running it up to a billion itterrations it
starts to matter.
As to the rest I was just stupidly forgetting that I'm in a loop. I'm faking a summation.
We don't have summation do we?
You also may want to make sure to declare some of the variables as float
or integer or whatever. The sum+= line might end up being a string
concatenation if not.
Yeah, I left out the declarations but it was all kosher.





Messages sorted by: Reverse Date, Date, Thread, Author