Multiply vs divide

JavaScript performance comparison

Test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
var x = 5 * 0.25,
    y = 5 * 0.5,
    z = 5 * 0.1,
    a = 5 * 2;
var x = 5 / 4,
    y = 5 / 2,
    z = 5 / 10,
    a = 5 / 0.5;

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

Miller Medeiros commented :

Browsers are smart, behavior might change based on the condition, see this perf test:

And read more about what might be going on this test: - TL;DR; JIT and caching are giving misleading results in this case.

I'm not saying you should always use division, I've seen different behavior based on browser and usage. This is probably a "premature optimization" unless you need to do something over an insane amount of data (eg. processing pixels on a large image).

Always profile your code and make sure it does apply to your use case. Also make sure your perf tests aren't biased.


Comment form temporarily disabled.

Add a comment