Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
endsWith vs at vs trimEnd vs Regex
(version: 1)
Comparing performance of:
endsWith vs at vs regex vs trimEnd
Created:
11 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function generateRandomText(length) { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 '; let result = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * chars.length); result += chars[randomIndex]; } return result; } const test = new Array(1000).map(e => generateRandomText(100))
Tests:
endsWith
test.filter(t => t.endsWith(" ") || t.endsWith("\n") || t.endsWith("\t") || t.endsWith("\r") || t.endsWith("\f") || t.endsWith("\v"))
at
test.filter(t =>{const l = t.at(t.length - 1); return l === " " || l === "\n" || l === "\t"|| l === "\r" || l === "\f" || l === "\v" })
regex
test.filter(t => /\s$/.test(t))
trimEnd
test.filter(t => (t.trimEnd().length !== t.length))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
endsWith
at
regex
trimEnd
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
endsWith
735815.3 Ops/sec
at
762689.1 Ops/sec
regex
790077.6 Ops/sec
trimEnd
782025.7 Ops/sec
Related benchmarks:
Text.data vs Text.nodeValue
Lodash _.some vs _.includes
Normalize path: JS Regex vs .endsWith vs .indexOf vs .slice
Regex vs Index vs StartsWith
Split vs Spread (randomized)
lodash _.some vs Array.some
string concat big string
normalize / trim text
generateRandomString
Comments
Confirm delete:
Do you really want to delete benchmark?