Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Pre-calc with bit shift vs Typical Code
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Typical Code
1307152.0 Ops/sec
Bit-shift
1783667.2 Ops/sec
Script Preparation code:
var cases = [ { nx: undefined, ny: 12 }, { ny: 12, nx: undefined }, { nx: undefined, ny: undefined }, { nx: 12, ny: 12 } ] var style = { transform: null }
Tests:
Typical Code
for (const {nx, ny} of cases) { if (nx !== undefined || ny !== undefined) { style.transform = nx !== undefined ? (ny !== undefined ? `translate(${nx}px, ${ny}px)` : `translateX(${nx}px)`) : `translateY(${ny}px)`; } }
Bit-shift
for (const {nx, ny} of cases) { const sx = nx !== undefined // state_x const sy = ny !== undefined // state_y const state = (sx && ! sy ? 1 : 0) | (sy && ! sx ? 2 : 0) | (sx && sy ? 4 : 0) | ( ! sx || ! sy ? 8 : 0) switch (state) { case 8: // neither style.transform = '' break case 4: // both style.transform = `translate(${nx}px, ${ny}px)` break case 2: // only y style.transform = `translateY(${ny}px)` break case 1: // only x style.transform = `translateX(${nx}px)` break; } }