Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Remove Duplicated Character Test
(version: 8)
Remove Duplicated Character Test
Comparing performance of:
indexOf vs Set vs object vs RegExp
Created:
5 months ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<div id='test'></div>
Script Preparation code:
const WORDS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/" let src = ''; let dst = ''; for (i = 0; i < 1024; i++) { src += WORDS[Math.floor(Math.random() * WORDS.length)]; }
Tests:
indexOf
[...src].forEach(ch=>{if(dst.indexOf(ch)===-1) dst += ch});
Set
[...(new Set([...src]))].forEach(ch=>dst+=ch);
object
let obj = {}; [...src].forEach(ch=>{if(!obj[ch]){obj[ch]=true;dst+=ch;}});
RegExp
dst = src.replace(/(.)(?=.*\1)/g,"")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
indexOf
Set
object
RegExp
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexOf
82439.9 Ops/sec
Set
69653.4 Ops/sec
object
66161.0 Ops/sec
RegExp
3200.0 Ops/sec
Related benchmarks:
aa vs bb
aaa vs bbb
eliminate duplicates from an array of strings
duplicates in string
regex vs loop for word count
sillyString 2
Meowww
endsWith vs at vs trimEnd vs Regex
JS string split fix Len
Comments
Confirm delete:
Do you really want to delete benchmark?