P12-Unencode

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
Orig
P12 = {
  unencode: function(list) {
    var listLen = list.length,
        result = [],
        i = 0,
        j = 0,
        itemCount = 0,
        item = null;

    for (; i < listLen; ++i) {
      currItem = list[i]
      if (currItem instanceof Array) {
        item = currItem[1];
        itemCount = currItem[0];
        for (; j < itemCount; ++j) {
          result.push(item)
        }
        item = null;
        itemCount = 0;
        j = 0;

      } else result.push(currItem);
    }
    return result;
  }
}

var encodeList = [
  [4, 'a'], 'b', [2, 'c'],
  [2, 'a'], 'd', [4, 'e']
]
P12.unencode(encodeList);
pending…
Mod
P12 = {
  unencode: function(list) {
    var listLen = list.length,
        result = [],
        i = 0,
        j = 0,
        itemCount = 0,
        item = null;

    for (; i < listLen; ++i) {
      currItem = list[i]
      if (currItem[1] !== undefined) {
        item = currItem[1];
        itemCount = currItem[0];
        for (; j < itemCount; ++j) {
          result.push(item)
        }
        item = null;
        itemCount = 0;
        j = 0;

      } else result.push(currItem);
    }
    return result;
  }
}

var encodeList = [
  [4, 'a'], 'b', [2, 'c'],
  [2, 'a'], 'd', [4, 'e']
]
P12.unencode(encodeList);
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