.replace() vs. join() (v83)

Revision 83 of this benchmark created on


Description

Using replace to remove newlines vs putting string in array and joining them

Setup

var arrayOfStrings = ['split','string','go']
var mystring = `
  split
  string
  go
`

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/\s+/g, ' ').trim()
result = mystring.replace(/\s+/g, ' ').trim()
ready
.join(' ')
result = arrayOfStrings.join(' ')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.