Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f1033a58b1
Fetching contributors…

Cannot retrieve contributors at this time

file 76 lines (68 sloc) 1.94 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<!doctype html>
<title>gf28 performance tests</title>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="gf28-compiled.js"></script>
<script src="deps.js"></script>
<script>
  //goog.require('gf28');
  goog.require('goog.testing.PerformanceTable');
  goog.require('goog.testing.PerformanceTimer');
  goog.require('goog.testing.PseudoRandom');
  goog.require('goog.testing.jsunit');
</script>
<div id="p"></div>
<script>

try {
  // generate lookup tables
  gf28.mul(1, 1);
} catch(e) {
  if (e instanceof ReferenceError) {
    alert("gf28 is not defined; gf28-compiled.js may not have been " +
          "generated. Try running 'make'.");
  }
}

var table = new goog.testing.PerformanceTable(
    goog.dom.getElement('p'), new goog.testing.PerformanceTimer(20));

var NUM_OPS = {
  'mul': 10000000,
  'div': 10000000,
  'inv': 10000000,
  'pow': 1000000,
  'add': 10000000,
}
var MAX_OPS = NUM_OPS['add'];

var inputs, outputs;

(function() {
  inputs = new Uint8Array(MAX_OPS * 2);
  outputs = new Uint8Array(MAX_OPS);
  var randomMock = new goog.testing.PseudoRandom(0, true);
  for (var i = 0; i < MAX_OPS; ++i) {
    inputs[i] = Math.floor(Math.random() * 256);
    inputs[MAX_OPS + i] = Math.floor(Math.random() * 255) + 1;
  }
  randomMock.uninstall();
})();

function runBinOp(opStr) {
  var op = gf28[opStr];
  var n = NUM_OPS[opStr];
  table.run(function() {
    for (var i = 0; i < n; ++i) {
      outputs[i] = op(inputs[i], inputs[n + i]);
    }
  }, n + ' ' + opStr + 's');
}

function runUnOp(opStr) {
  var op = gf28[opStr];
  var n = NUM_OPS[opStr];
  table.run(function() {
    for (var i = 0; i < n; ++i) {
      outputs[i] = op(inputs[n + i]);
    }
  }, n + ' ' + opStr + 's');
}

testMul = goog.partial(runBinOp, 'mul');
testDiv = goog.partial(runBinOp, 'div');
testInv = goog.partial(runUnOp, 'inv');
testAdd = goog.partial(runBinOp, 'add');
testPow = goog.partial(runBinOp, 'pow');
</script>
Something went wrong with that request. Please try again.