Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n') #3
(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:
// 1. 줄바꿈이 없는 매우 긴 문자열 생성 (약 100KB) var longStr = "a".repeat(100000); // 2. 끝부분에만 줄바꿈이 있는 긴 문자열 var longStrWithNewline = longStr + "\n"; var regex = /\r\n|\n/;
Tests:
_.replace
// 줄바꿈이 없어도 전체 스캔 발생 _.replace(longStr, regex, '');
.indexOf(/n)
// 줄바꿈이 없으므로 즉시 false 반환 -> replace 실행 안 함 if (longStr.indexOf('\n') > -1 || longStr.indexOf('\r') > -1) { longStr.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
219677.8 Ops/sec
.indexOf(/n)
211569.6 Ops/sec
Related benchmarks:
Array Remove vs String Replace
replace vs splitjoin
replace vs splitjoin
replace vs splitjoin
replace vs splitjoin
Trimming leading/trailing string of characters
Asterisk character test
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n') #2
_.replace(line, /\r\n|\n/, '') vs .indexOf('/n') #4
Comments
Confirm delete:
Do you really want to delete benchmark?