Оптимизация длинных списков логических значений

Benchmark created by lkart on


Description

For http://habrahabr.ru/post/149176/ Russian translation of http://coding.smashingmagazine.com/2011/10/19/optimizing-long-lists-of-yesno-values-with-javascript/

Test runner

Ready to run.

Testing in
TestOps/sec
Использование Base 36
parseInt('1001011000', 2).toString(36);
parseInt('go', 36).toString(2);
ready
Упаковка 16 значений в один символ
function pack( /* string */ values) {
  var chunks = values.match(/.{1,16}/g),
      packed = '';
  for (var i = 0; i < chunks.length; i++) {
    packed += String.fromCharCode(parseInt(chunks[i], 2));
  }
  return packed;
}

function unpack( /* string */ packed) {
  var values = '';
  for (var i = 0; i < packed.length; i++) {
    values += packed.charCodeAt(i).toString(2);
  }
  return values;
}

var booleanList = '1001011000';
var packedString = pack(booleanList);
var unpackedString = unpack(packedString);
ready

Revisions

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