jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Given a string containing any combinations of the 4 tokens BEGIN END Y N, calculate the number of "valid" logs contained within.
Logs are valid if they begin with BEGIN and end with END, with no nesting - that is, the string BEGIN BEGIN Y N END END contains only one valid log: BEGIN Y N END
.
BEGIN END => 1 BEGIN Y END => 1 BEGIN Y N END BEGIN => 1 END END Y BEGIN N Y N BEGIN Y END => 1 END BEGIN => 0
const regexAnswers = [];
const stackAnswers = [];
const tokens = ["BEGIN", "END", "Y", "N"];
const strings = [];
for (let i = 1; i <= 10; i++) {
const length = Math.floor(Math.random() * 10);
const stringBuild = [];
for (let j = 0; j < length; j++) {
stringBuild.push(tokens[Math.floor(Math.random() * tokens.length)]);
}
strings.push(stringBuild.join(" "));
}
stackAnswers.forEach((stackAnswer, index) => {
if (stackAnswer !== regexAnswers[index]) {
console.log("MISMATCH");
}
});
Ready to run.
Test | Ops/sec | |
---|---|---|
regex |
| ready |
stack |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.