wip

Benchmark created on


Setup

const positions = [
  'f11',
  'e10',
  'f10',
  'g10',
  'd9',
  'e9',
  'f9',
  'g9',
  'h9',
  'c8',
  'd8',
  'e8',
  'f8',
  'g8',
  'h8',
  'i8',
  'b7',
  'c7',
  'd7',
  'e7',
  'f7',
  'g7',
  'h7',
  'i7',
  'k7',
  'a6',
  'b6',
  'c6',
  'd6',
  'e6',
  'f6',
  'g6',
  'h6',
  'i6',
  'k6',
  'l6',
  'a5',
  'b5',
  'c5',
  'd5',
  'e5',
  'f5',
  'g5',
  'h5',
  'i5',
  'k5',
  'l5',
  'a4',
  'b4',
  'c4',
  'd4',
  'e4',
  'f4',
  'g4',
  'h4',
  'i4',
  'k4',
  'l4',
  'a3',
  'b3',
  'c3',
  'd3',
  'e3',
  'f3',
  'g3',
  'h3',
  'i3',
  'k3',
  'l3',
  'a2',
  'b2',
  'c2',
  'd2',
  'e2',
  'f2',
  'g2',
  'h2',
  'i2',
  'k2',
  'l2',
  'a1',
  'b1',
  'c1',
  'd1',
  'e1',
  'f1',
  'g1',
  'h1',
  'i1',
  'k1',
  'l1',
]

function createBoard() {
  return {
    f11: null,
    e10: null,
    f10: null,
    g10: null,
    d9: null,
    e9: null,
    f9: null,
    g9: null,
    h9: null,
    c8: null,
    d8: null,
    e8: null,
    f8: null,
    g8: null,
    h8: null,
    i8: null,
    b7: null,
    c7: null,
    d7: null,
    e7: null,
    f7: null,
    g7: null,
    h7: null,
    i7: null,
    k7: null,
    a6: null,
    b6: null,
    c6: null,
    d6: null,
    e6: null,
    f6: null,
    g6: null,
    h6: null,
    i6: null,
    k6: null,
    l6: null,
    a5: null,
    b5: null,
    c5: null,
    d5: null,
    e5: null,
    f5: null,
    g5: null,
    h5: null,
    i5: null,
    k5: null,
    l5: null,
    a4: null,
    b4: null,
    c4: null,
    d4: null,
    e4: null,
    f4: null,
    g4: null,
    h4: null,
    i4: null,
    k4: null,
    l4: null,
    a3: null,
    b3: null,
    c3: null,
    d3: null,
    e3: null,
    f3: null,
    g3: null,
    h3: null,
    i3: null,
    k3: null,
    l3: null,
    a2: null,
    b2: null,
    c2: null,
    d2: null,
    e2: null,
    f2: null,
    g2: null,
    h2: null,
    i2: null,
    k2: null,
    l2: null,
    a1: null,
    b1: null,
    c1: null,
    d1: null,
    e1: null,
    f1: null,
    g1: null,
    h1: null,
    i1: null,
    k1: null,
    l1: null,
  }
}

Test runner

Ready to run.

Testing in
TestOps/sec
loop
function parseBoard(source) {
  const normalized = source
    .replaceAll('11', '___________')
    .replaceAll('10', '__________')
    .replaceAll('9', '_________')
    .replaceAll('8', '________')
    .replaceAll('7', '_______')
    .replaceAll('6', '______')
    .replaceAll('5', '_____')
    .replaceAll('4', '____')
    .replaceAll('3', '___')
    .replaceAll('2', '__')
    .replaceAll('1', '_')
    .replaceAll('/', '')
    
  return normalized
}

parseBoard('b/qbk/n1b1n/r5r/ppppppppp/11/5P5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1')
ready
loop 2
function parseBoard(source) {
  let normalized = ''

  for (let i = 0; i < source.length; i++) {
    switch (source[i]) {
      case '1':
        switch (source[i + 1]) {
          case '0':
          	i++
            normalized += '__________';
            continue
          case '1':
            i++
            normalized += '___________';
            continue
          default:
            normalized += '_';
            continue
        }
      case '2':
        normalized += '__';
        continue
      case '3':
        normalized += '___';
        continue
      case '4':
        normalized += '____';
        continue
      case '5':
        normalized += '_____';
        continue
      case '6':
        normalized += '______';
        continue
      case '7':
        normalized += '_______';
        continue
      case '8':
        normalized += '________';
        continue
      case '9':
        normalized += '_________';
        continue
      case '/':
      	continue
      default:
        normalized += source[i]
    }
  }

  return normalized
}

parseBoard('b/qbk/n1b1n/r5r/ppppppppp/11/5P5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1')
ready

Revisions

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