Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
path2d-vs-math
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/125.0.0.0 Safari/537.36 Edg/125.0.0.0
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
path2d
2013615.0 Ops/sec
math
1544273.8 Ops/sec
Script Preparation code:
var boundingRect = { x: 10, y: 10, width: 100, height: 50 }; var x = 20; var y = 20; const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const rectanglePath2D = new Path2D(); rectanglePath2D.rect(boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height); function calculateViaPath2d() { return ctx.isPointInPath(rectanglePath2D, x, y); } const maxX = boundingRect.x + boundingRect.width; const maxY = boundingRect.y + boundingRect.height; function calculateViaMath() { return (boundingRect.x <= x) && (x <= maxX) && (boundingRect.y <= y) && (x <= maxY) }
Tests:
path2d
calculateViaPath2d()
math
calculateViaMath()