Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Regex vs split for Authorization Headers
Is it faster to get the meat from an Authorization header by splitting on the space? or using a regex replace and trim?
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0
Browser:
Firefox 151
Operating system:
Linux
Device Platform:
Desktop
Date tested:
11 days ago
Test name
Executions per second
Split on space
10070045.0 Ops/sec
Regex replace and trim
10948417.0 Ops/sec
Regex replace without global
22173222.0 Ops/sec
Script Preparation code:
var authHeader = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJkZnMiOiJhZGZzamxrO2FzZGZqbGs7c2RmYWtqbDthc2RmamtsIiwiaXNzIjoiaHR0cHM6Ly92ZXJ5LnZlcnkudmVyeS52ZXJ5LnZlcnkubG9uZy5leGFtcGxlLmNvbSJ9.RGmluP8NjlKuiow57PkkAZLUCwclllRBPURJU7Hajmo';
Tests:
Split on space
authHeader.split(' ')[1]
Regex replace and trim
authHeader.replace(/Bearer/g,'').trim()
Regex replace without global
authHeader.replace(/Bearer /,'')