Regex vs split/join - actual replace

Now regex flies and split crawls. BTW that regex match split plus join is what jQuery's removeClass() does - just much worse. Had to double check just in case that there's some hidden trick involved.
3 years ago
User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
Test name Executions per second
Regex 1280865.0 Ops/sec
Regex match as Split - jQuery style :-) 385368.3 Ops/sec
Split and Join 337364.6 Ops/sec
Script Preparation code:
Tests:
  • Regex

  • Regex match as Split - jQuery style :-)

  • Split and Join

Open this result on MeasureThat.net