Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0
Firefox 113
Windows
Desktop
one year ago
Test name Executions per second
regex 5412793.0 Ops/sec
trim 7305401.0 Ops/sec
Script Preparation code:
AخA
 
var string = '    fsajdf asdfjosa fjoiawejf oawjfoei jaosdjfsdjfo sfjos 2324234 sdf safjao j o        sdlfks dflks l      ';
var string2 = '                         ';
var string3 = '                                     a                                                 ';
var string4 = ' ';
var pattern = /^\s*$/;
Tests:
  • regex

     
    pattern.test(string);
    pattern.test(string2);
    pattern.test(string3);
    pattern.test(string4);
  • trim

     
    string.trim() === '';
    string2.trim() === '';
    string3.trim() === '';
    string4.trim() === '';