Counting words space - match vs split
Date tested:
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
1456971.0 Ops/sec
Match
1537890.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
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