Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Height calculations: RegEx vs split()
Calculating height in inches from a string
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/142.0.0.0 Safari/537.36 OPR/126.0.0.0 (Edition developer)
Browser:
Opera 126
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
RegEx
28153.5 Ops/sec
split()
25801.2 Ops/sec
Script Preparation code:
const heights = [`6'`, `5'3"`, `11"`, `0'8"`, `4'0"`]
Tests:
RegEx
const heightRegex = /(?:^|(\d+)['])(?:$|(\d+)["])/ for (const height of heights) { const result = height.match(heightRegex); console.log("Height in inches: ", ((result[1] ?? 0) * 12) + (result[2] ?? 0)); }
split()
for (const height of heights) { const hasFeet = height.includes(`'`); const hasInches = height.includes(`"`); let value = 0 if (hasFeet && hasInches) { const heightArray = height.split(`'`) const feet = Number(heightArray[0]) const inches = Number(heightArray[1]?.split(`"`)[0]) value = feet * 12 + inches; } else if (hasFeet) { value = Number(height.split(`'`)[0]) * 12 } else if (hasInches) { value = Number(height.split(`"`)[0]); } console.log("Height in inches: ", value) }