Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Substr vs Substring vs Slice v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Substr
439702.5 Ops/sec
Substring
434490.0 Ops/sec
Slice
404945.7 Ops/sec
Script Preparation code:
function getRandomColor() { const letras = "0123456789ABCDEF"; let color = "#"; for (let i = 0; i < 6; i++) { color += letras[Math.floor(Math.random() * 16)]; } return color; }
Tests:
Substr
function getContrast(hexcolor) { const red = parseInt(hexcolor.substr(1, 2), 16); const green = parseInt(hexcolor.substr(3, 2), 16); const blue = parseInt(hexcolor.substr(5, 2), 16); const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255; return luminance > 0.5 ? "black" : "white"; } const color= getRandomColor(); const textColor = getContrast(color);
Substring
function getContrast(hexcolor) { const red = parseInt(hexcolor.substring(1, 2), 16); const green = parseInt(hexcolor.substring(3, 2), 16); const blue = parseInt(hexcolor.substring(5, 2), 16); const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255; return luminance > 0.5 ? "black" : "white"; } const color= getRandomColor(); const textColor = getContrast(color);
Slice
function getContrast(hexcolor) { const red = parseInt(hexcolor.slice(1, 2), 16); const green = parseInt(hexcolor.slice(3, 2), 16); const blue = parseInt(hexcolor.slice(5, 2), 16); const luminance = (0.2126 * red + 0.7152 * green + 0.0722 * blue) / 255; return luminance > 0.5 ? "black" : "white"; } const color= getRandomColor(); const textColor = getContrast(color);