split, substring, regex and replace

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
split
var str = 'test@example.com'
var username = str.split('@')[0]
ready
substring
var str = 'test@example.com'
var username = str.substring(0, str.indexOf('@'))
ready
regex
var str = 'test@example.com'
var username = str.match(/^([^@]*)@/)[1]
ready
replace
var str = 'test@example.com'
var username = str.replace(/@.*$/, '');
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.