Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
fast sin cos vs math sin cos
testing faster functions
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/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Math.sin
773096.2 Ops/sec
Math.cos
776404.9 Ops/sec
fastSin
631497.8 Ops/sec
fastCos
569495.2 Ops/sec
lookupSin
22433.9 Ops/sec
lookupCos
22587.8 Ops/sec
Script Preparation code:
var random = new Float64Array(1000); var lSin = new Float64Array(1000); var lCos = new Float64Array(1000); for (let i = 0; i < 1000; i++) { random[i] = Math.random() * 1000000; } for (let i = 0; i < 1000; i++) { lSin[i] = Math.sin(i * Math.PI / 1000); lCos[i] = Math.sin(i * Math.PI / 1000); } function fastCos(x) { x += 1.57079632; x -= ((x > 3.14159265) ? 6.28318530 : 0); return (x < 0) ? (1.27323954 * x) + (0.40528473 * x * x) : (1.27323954 * x) - (0.40528473 * x * x); } function fastSin(x) { x -= ((x > 3.14159265) ? 6.28318530 : 0); return (x < 0) ? (1.27323954 * x) + (0.40528473 * x * x) : (1.27323954 * x) - (0.40528473 * x * x); } function lookupSin(x) { return lSin[Math.round((x % 1000) * 1000) / 1000]; } function lookupCos(x) { return lSin[Math.round((x % 1000) * 1000) / 1000]; }
Tests:
Math.sin
for (let i = 0; i < 1000; i++) { Math.sin(random[i]); }
Math.cos
for (let i = 0; i < 1000; i++) { Math.cos(random[i]); }
fastSin
for (let i = 0; i < 1000; i++) { fastSin(random[i]); }
fastCos
for (let i = 0; i < 1000; i++) { fastCos(random[i]); }
lookupSin
for (let i = 0; i < 1000; i++) { lookupSin(random[i]); }
lookupCos
for (let i = 0; i < 1000; i++) { lookupCos(random[i]); }