Counting words space - match vs split

6 years ago
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Test name Executions per second
Split 1456970.8 Ops/sec
Match 1537889.9 Ops/sec
Script Preparation code:
AخA
 
var regex = /\s/
var regexGlobal = /\s/g
var str = 'foo bar baz\n\nfoo bar'
Tests:
  • Split

     
    str.split(regex).length
  • Match

     
    str.match(regexGlobal).length
Open this result on MeasureThat.net