b26enc_impls

JavaScript performance comparison

Test case created by Aluísio A. S. G.

Preparation code

<script>
var b26enc_recursive, b26enc_iter_string, b26enc_iter_array, join$ = [].join;
b26enc_recursive = function(n){
  var chr, ref$;
  chr = String.fromCharCode;
  switch (false) {
  case !(-26 < n && n < 26):
    return chr(65 + n);
  default:
    return b26enc_recursive(Math.floor(n / 26)) + chr(65 + ((n) % (ref$ = 26) + ref$) % ref$);
  }
};
b26enc_iter_string = function(n){
  var chrval, res, ref$;
  chrval = function(n){
    return String.fromCharCode(65 + n);
  };
  res = '';
  while (!(-26 < n && n < 26)) {
    res += chrval(((n) % (ref$ = 26) + ref$) % ref$);
    n = Math.floor(n / 26);
  }
  return chrval(n) + res;
};
b26enc_iter_array = function(n){
  var chrval, res, res$, v, ref$;
  chrval = function(n){
    return String.fromCharCode(65 + n);
  };
  res$ = [];
  while (!(-26 < n && n < 26)) {
    v = chrval(((n) % (ref$ = 26) + ref$) % ref$);
    n = Math.floor(n / 26);
    res$.push(v);
  }
  res = res$;
  return join$.call([chrval(n)].concat(res), '');
};
</script>
<script>
Benchmark.prototype.setup = function() {
    var testval = Math.floor(Math.random() * 4294967296);
};
</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
Recursive
b26enc_recursive(testval);
pending…
Iterative, result in string
b26enc_iter_string(testval);
pending…
Iterative, result in array
b26enc_iter_array(testval);
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment