Detecting all-zero base64 string (v2)

Revision 2 of this benchmark created on


Setup

const base64 = (arr) => btoa(new TextDecoder().decode(arr))

const allZeros =  base64(new Uint8Array(512 * 1024))

let failEarly = new Uint8Array(512 * 1024)
failEarly[10000] = 1
failEarly = base64(failEarly)

let failLate = new Uint8Array(512 * 1024)
failLate[500000] = 1
failLate = base64(failLate)

function isAllZeros(s) {
  return /^A*=*$/.test(s)
}

function isNotAllZeros(s) {
  return /[^A=]/.test(s)
}

Test runner

Ready to run.

Testing in
TestOps/sec
isAllZeros - fail early
isAllZeros(failEarly)
ready
isAllZeros - fail late
isAllZeros(failLate)
ready
isAllZeros - pass
isAllZeros(allZeros)
ready
isNotAllZeros - fail early
isNotAllZeros(failEarly)
ready
isNotAllZeros - fail late
isNotAllZeros(failLate)
ready
isNotAllZeros - all zeros
isNotAllZeros(allZeros)
ready

Revisions

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