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
// Array to store the generated strings
let strings = [];
// Loop to generate 1000 strings
for (let i = 0; i < 100000; i++) {
// Generate a random length for the string between 60 and 120 characters
let length = Math.floor(Math.random() * 61) + 60;
// Generate a random chance for including a thanks string (50% chance)
let includeThanks = Math.random() < 0.5;
// Generate the string
let str = '';
// If including a thanks string
if (includeThanks) {
// 50% chance to include at the beginning or the end
if (Math.random() < 0.5) {
// Include at the beginning
str += ['thanks', 'ty', 'tysm', 'thank you'][Math.floor(Math.random() * 4)] + ' ';
}
// Generate the rest of the string
let remainingLength = length - str.length;
while (remainingLength > 0) {
// 50% chance to include a random character or a space
if (Math.random() < 0.5) {
// Include a space
str += ' ';
remainingLength--;
} else {
// Include a random character
str += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
remainingLength--;
}
}
// 50% chance to include at the end
if (Math.random() < 0.5) {
str += ' ' + ['thanks', 'ty', 'tysm', 'thank you'][Math.floor(Math.random() * 4)];
}
} else {
// Generate the rest of the string without including a thanks string
while (str.length < length) {
// 50% chance to include a random character or a space
if (Math.random() < 0.5) {
// Include a space
str += ' ';
} else {
// Include a random character
str += String.fromCharCode(Math.floor(Math.random() * 26) + 97);
}
}
}
// Add the generated string to the array
strings.push(str);
}
// Output the array of strings
console.log(strings);
const THANKS_STRINGS = [
/thanks+s*/i,
/thank you+u*/i,
/thx+x*/i,
/tysm+m*/i,
/thank u+u*/i,
/\bty+y*\b/i
];
const isPotentialThanks = (content) => {
for (const t_str of THANKS_STRINGS) {
if (content.match(t_str)) {
return true;
}
}
return false;
};
const isPotentialThanks02 = (content) => {
for (const t_str of THANKS_STRINGS) {
if (t_str.test(content)) {
return true;
}
}
return false;
};
const reg = /\b(thanks+s*|thank you+u*|thx+x*|tysm+m*|thank u+u*|ty+y*)\b/i;
const isPotentialThanks2 = (content) => {
return content.match(reg)
};
const isPotentialThanks3 = (content) => {
return content.match(/thanks+s*/i) || content.match(/thank you+u*/i) || content.match(/thx+x*/i) || content.match(/tysm+m*/i) || content.match(/thank u+u*/i) || content.match(/\bty+y*\b/i);
};
/*
const tystrings2 = [
'thanks', 'thank you', 'thx', 'tysm', 'thank u', 'ty'
]
const t = (content)=>{
for (const i of tystrings2){
if(content.includes(i)){
return true
}
}
}
*/
Ready to run.
Test | Ops/sec | |
---|---|---|
using regex |
| ready |
using test |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.