# rational.js vs fraction.js vs ratio.js - subtract, multiply, add, divide

## JavaScript performance comparison

Revision 6 of this test case created

## Preparation code

``<script src="https://raw.github.com/acerix/rational.js/master/dist/rational.js"></script><script src="https://raw.github.com/ekg/fraction.js/master/fraction.js"></script><script src="https://raw.github.com/LarryBattle/Ratio.js/master/lib/Ratio-0.3.11.min.js"></script><script>  Benchmark.prototype.setup = function() {    var test_cases = [      [3466463461, 134534331],      [12312337, 334534535],      [3453453, 3653450],      [53453453411, 365340],      [123453453, 3653453450],      [-173646341, 36345340],      [245345213, 2353523],      [212151121, 234234666],      [234235535, 234234666],      [-656755537, 65676767]    ];        var float_1 = 1 / 10;    var float_2 = 111 / 3;        var rat_1 = rat.fromValues(1, 10);    var rat_2 = rat.fromValues(111, 3);        var ratio_1 = Ratio(1);    var ratio_2 = Ratio(1);        var frac_1 = new Fraction(1);    var frac_2 = new Fraction(1);      };</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…
Ratio.js
``for (var i in test_cases) {  ratio_1 = Ratio( test_cases[i][0], test_cases[i][1] );  ratio_2 = ratio_2.subtract(ratio_1).reduce().multiply(ratio_1).reduce().add(ratio_1).reduce().divide(ratio_1).reduce();}``
pending…
fraction.js
``for (var i in test_cases) {  frac_1 = new Fraction( test_cases[i][0], test_cases[i][1] );  frac_2 = frac_2.subtract(ratio_1).multiply(ratio_1).add(ratio_1).divide(ratio_1);}``
pending…

## 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

Comment form temporarily disabled.