Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n')
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n')
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
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:
Chrome 142
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
_.replace
28899120.0 Ops/sec
.indexOf(/n)
33167826.0 Ops/sec
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, ''); }