Detecting all-zero base64 string

Benchmark created on


Setup

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

const pass =  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)
}

Test runner

Ready to run.

Testing in
TestOps/sec
Fail early
isAllZeros(failEarly)
ready
Fail late
isAllZeros(failLate)
ready
Pass
isAllZeros(pass)
ready

Revisions

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