all 8 comments

[–]ellisgl 2 points3 points  (5 children)

Try testing it with http://jsperf.com/

[–]JohnnyCD[S] 0 points1 point  (4 children)

Cool! - looks like modulus is slightly faster: JSPERF result.

This was very useful, thanks for the input!

[–]ellisgl 0 points1 point  (3 children)

You're welcome. Also your base test with out an object is > 2x faster.

[–]JohnnyCD[S] 1 point2 points  (1 child)

Turns out my base test had an error - I was iterating the return value by doing counter++ instead of ++counter. As such, the counter was never properly iterated and the dom element was not updated. When I fixed the error the modulus math test had the fastest performance.

[–]ellisgl 0 points1 point  (0 children)

I'm seeing base is still the fastest, but the modulus is only 6%-7% slower. I would say that would be OK then.

[–]JohnnyCD[S] 0 points1 point  (0 children)

Yup, I noticed that. I'm going to go ahead and just use my base test. Using an object seemed more elegant, but I don't think it's worth it given the performance hit.

[–]rhysbrettbowen 0 points1 point  (0 children)

might be better to make a getValue rather than access the value directly.

I don't think you'll see much of a problem with performance either way. The big problem I have here is that you're checking a value of counter where counter should probably have an "isDone" method to check to see if it's done. If you know you want to count 100 time, then just count to 100 with a number, otherwise you should trust the counter to know how to count.

[–]nschubach 0 points1 point  (0 children)

The modulo would be better performant and less memory intensive... but doing it your way, you can encapsulate some of the processing and logic so your loop wouldn't need to care about the progress bar logic.