main test

Benchmark created on


Setup

// 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
		}
	}
	
}
*/

Test runner

Ready to run.

Testing in
TestOps/sec
using regex


for (const msg of strings){
	isPotentialThanks(msg)
}


ready
using test
for (const msg of strings){
	isPotentialThanks02(msg)
}

ready

Revisions

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