Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Sanitize
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
From preact sources
26837.6 Ops/sec
Simple solution
21322.2 Ops/sec
ChatGPT solution
5815.6 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Tests:
From preact sources
const strings = [ 'dsafsdafasdf', '>asdf<span>sdfsdf', 'sdfdsf&sdf"sdfadsfs\'sadf\nsadfasdf', '', '123#<!-- sdfsdf -->', ] const ENCODED_ENTITIES = /["&<]/ function encodeEntities(str) { // Skip all work for strings with no entities needing encoding: if (str.length === 0 || ENCODED_ENTITIES.test(str) === false) return str let last = 0, i = 0, out = '', ch = '' // Seek forward in str until the next entity char: for (; i < str.length; i++) { switch (str.charCodeAt(i)) { case 34: ch = '"' break case 38: ch = '&' break case 60: ch = '<' break default: continue } // Append skipped/buffered characters and the encoded entity: if (i !== last) out = out + str.slice(last, i) out = out + ch // Start the next seek/buffer after the entity's offset: last = i + 1 } if (i !== last) out = out + str.slice(last, i) return out } for (let i = 0; i < 100; i++) { strings.map(encodeEntities) }
Simple solution
const strings = [ 'dsafsdafasdf', '>asdf<span>sdfsdf', 'sdfdsf&sdf"sdfadsfs\'sadf\nsadfasdf', '', '123#<!-- sdfsdf -->', ] const sanitizeMap = { '<': '<', '>': '>', '"': '"', } const sanitize = value => { if (value === undefined || value == null) { return null } return String(value).replace(/[<>"]/g, char => sanitizeMap[char]) } for (let i = 0; i < 100; i++) { strings.map(sanitize) }
ChatGPT solution
const strings = [ 'dsafsdafasdf', '>asdf<span>sdfsdf', 'sdfdsf&sdf"sdfadsfs\'sadf\nsadfasdf', '', '123#<!-- sdfsdf -->', ] function sanitizeChatGPT(value) { if (!value) return '' return value .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, ''') } for (let i = 0; i < 100; i++) { strings.map(sanitizeChatGPT) }