Script Preparation code:
x
 
const strings = [];
for (let i = 0; i < 1000; ++i) {
  const string = i % 2 === 0 ? '    ' : (Math.random() * 100000).toFixed(0).toString()
  strings.push(string);
}
window.strings = strings;
Tests:
  • Trim

     
    function isNullOrWhitespace(str) {
      return !str || !str.trim();
    }
    window.strings.forEach(string => isNullOrWhitespace(string));
  • RegExp

     
    const regExp = /^ *$/;
    function isNullOrWhitespace(str) {
      return !str || regExp.test(str);
    }
    window.strings.forEach(string => isNullOrWhitespace(string));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Trim
    RegExp

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 months ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131 on Windows
View result in a separate tab
Test name Executions per second
Trim 93113.4 Ops/sec
RegExp 45577.9 Ops/sec