• How to measure performance

Question related to mission First Word


Hi. How do you go about deciding on which pattern is best? I tried using performance.now() in the browser, but each time you run it you get a different time, and times were kind of similar for either pattern.

function firstWord(a,b) {
return a.match(/\w+'?\w*/g)[0];

var firstWord = a => a.match(/[a-z']+/i)[0];

tests console.log(firstWord("Hello world"));
console.log(firstWord(" a word "));
console.log(firstWord("don't touch it"));
console.log(firstWord("greetings, friends"));
console.log(firstWord("... and so on ..."));