Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n')
(version: 1)
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n')
Comparing performance of:
_.replace vs .indexOf(/n)
Created:
4 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var shortString = "Short string without newline"; var longString = "This is a very long string that represents a large amount of text data potentially copied from a web upload form. It does not contain any newline characters initially but we want to check the performance impact of running a regex replace vs a simple indexOf check."; var longStringWithNewline = longString + "\n" + longString; var regex = /\r\n|\n/;
Tests:
_.replace
_.replace(longString, regex, '');
.indexOf(/n)
if (longString.indexOf('\n') > -1 || longString.indexOf('\r') > -1) { longString.replace(regex, ''); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.replace
.indexOf(/n)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Whale/4.35.351.13 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.replace
28899120.0 Ops/sec
.indexOf(/n)
33167826.0 Ops/sec
Related benchmarks:
replace vs substring vs slice from beginning (+ brackets, substr, compiled vs inline regex)
replace all performance javascript
looking up the last character of a string
regex vs chars
String.replace vs String.replaceAll
sa sad test
replaceAll vs regex replace for a newLine
replaceAll vs regex replace for a newLine using html tags
replaceAll vs regex replace fefw
Comments
Confirm delete:
Do you really want to delete benchmark?