rational vs float - subtract, multiply, add, divide

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<script src="//raw.github.com/acerix/rational.js/master/src/rat.js">
</script>
<script>
Benchmark.prototype.setup = function() {
    var test_cases = [
      [1, 11],
      [3, 360],
      [5411, 360],
      [123, 360],
      [171, 360],
      [13, 23523],
      [21, 666],
      [65535, 666],
      [-65537, 667]
    ];
   
    var float_1 = 0.1;
    var float_2 = 11.1;
   
    var rat_1 = rat.fromValues(1, 10);
    var rat_2 = rat.fromValues(111, 10);
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native float approximation
for (var i in test_cases) {
  float_1 = test_cases[i][0] / test_cases[i][1];
  float_2 = ((float_2 - float_1) * float_1 + float_1) / float_1;
}
pending…
rational.js calculation
for (var i in test_cases) {
  rat.set(rat_1, test_cases[i][0], test_cases[i][1]);
  rat.subtract(rat_2, rat_2, rat_1);
  rat.multiply(rat_2, rat_2, rat_1);
  rat.add(rat_2, rat_2, rat_1);
  rat.divide(rat_2, rat_2, rat_1);
}
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment