Files
deepgrain-foundry/tools/experiments/slope-cost.js
T
44r0n7andClaude Opus 5.5 578b55316b Sloped belts hold their load with moving cleats (t42); sloped filters are downhill shaking screens (t43)
The magic grip is gone: cleats every 8 face cells, 6 grains tall, carry
pockets uphill (about 71 grains/s against 90 flat) and overflow rolls
back. Sloped filters always run downhill; grains travel by gravity and
a shake, and sorting stays exact. Drawing needs another pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 19:47:59 -04:00

35 lines
1.8 KiB
JavaScript

// Many loaded slopes, with a fresh deterministic world for each timing sample.
const { performance } = require('perf_hooks');
const { load, flatWorld } = require(process.env.DG_HARNESS || '../../test/harness');
const { run } = load();
const assert = require('node:assert/strict');
const samples=[];
for(let sample=0;sample<6;sample++) {
flatWorld(run,1024,512,496);
run(`RS=7;money=1e9;AMB.fill(20);temp.fill(20);hot.fill(0);
for(let row=0;row<6;row++)for(let col=0;col<8;col++)for(let k=0;k<12;k++){
const bx=col*30+4+k,by=row*18+35-k;
placeBlock(BP_BELT_UP,1,bx,by,true);
for(let x=bx*4;x<bx*4+4;x++){const y=beltFaceY(BP_BELT_UP,bx,by,x);for(let h=1;h<=4;h++)setCell((y-h)*W+x,SAND,20,0);}
}
for(let k=0;k<60;k++)simTick();`);
const start=performance.now();run('for(let k=0;k<240;k++)simTick();');
if(sample) samples.push((performance.now()-start)/240);
}
assert(samples.length===5 && samples.every(n=>Number.isFinite(n) && n>0));
samples.sort((a,b)=>a-b);
console.log(`576 loaded slope blocks, median ${samples[2].toFixed(3)} ms/tick; samples ${samples.map(v=>v.toFixed(3)).join(', ')}`);
// No slopes: isolate the extra guards in the shared powder hot loop.
flatWorld(run,512,384,376);
run('RS=7;for(let y=32;y<350;y+=2)for(let x=32;x<480;x++){mat[y*W+x]=SAND;mat[(y+1)*W+x]=STONE;}');
const powderSamples=[];
for(let sample=0;sample<6;sample++) {
const start=performance.now();
run('for(let k=0;k<30;k++)for(let y=32;y<350;y+=2)for(let x=32;x<480;x++)powder(y*W+x,x,y,SAND);');
if(sample)powderSamples.push(performance.now()-start);
}
assert(powderSamples.length===5 && powderSamples.every(n=>Number.isFinite(n) && n>0));
powderSamples.sort((a,b)=>a-b);
console.log(`2.14M powder calls without cleats, median ${powderSamples[2].toFixed(2)} ms`);