Constant?

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
==
function equals(test, secret) {
  // String comparison that does not leak timing information
  let diffs = test.length !== secret.length ? 1 : 0;
  for (let i = 0; i < test.length; i++) if (test[i] !== secret[i]) diffs++;
  return diffs == 0;
}

equals("12345678901234567890", "12345678901234567890")
ready
!=
function equals(test, secret) {
  // String comparison that does not leak timing information
  let diffs = test.length !== secret.length ? 1 : 0;
  for (let i = 0; i < test.length; i++) if (test[i] !== secret[i]) diffs++;
  return diffs == 0;
}

equals("12345678901234567890", "01234567890123456789")
ready

Revisions

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