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/139.0.0.0 Safari/537.36
Browser:
Chrome 139
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Math.sin
400K/s
Math.cos
389K/s
fastSin
371K/s
fastCos
369K/s
lookupCos
7K/s
lookupSin
7K/s
View exact numbers
Test name
Executions per second
✓
Math.sin
400,151 Ops/sec
Math.cos
388,715 Ops/sec
fastSin
370,659 Ops/sec
fastCos
369,076 Ops/sec
lookupCos
7,433 Ops/sec
lookupSin
7,232 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]); }