-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench-pixel-vs-trinary.html
More file actions
324 lines (282 loc) · 13.5 KB
/
bench-pixel-vs-trinary.html
File metadata and controls
324 lines (282 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pixel Memory Benchmark — Binary vs Trinary</title>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body { background:#000; color:#f0f0f0; font-family:'JetBrains Mono',monospace; padding:24px; min-height:100vh; }
h1 { font-size:18px; color:#8844FF; margin-bottom:4px; }
.sub { font-size:11px; color:#333; margin-bottom:24px; }
.grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:20px; }
.card { background:#0a0a0a; border:1px solid #141414; padding:16px; }
.card h2 { font-size:12px; color:#555; text-transform:uppercase; letter-spacing:0.1em; margin-bottom:12px; }
.metric { margin-bottom:8px; }
.metric .label { font-size:10px; color:#444; }
.metric .value { font-size:20px; font-weight:700; }
.binary .value { color:#4488FF; }
.trinary .value { color:#FF6B2B; }
.bar-wrap { height:6px; background:#111; margin:4px 0 8px; border-radius:3px; overflow:hidden; }
.bar { height:100%; border-radius:3px; transition:width 0.6s ease; }
.bar.bin { background:linear-gradient(90deg,#4488FF,#8844FF); }
.bar.tri { background:linear-gradient(90deg,#FF6B2B,#FF2255); }
.bench { background:#050505; border:1px solid #1a1a1a; padding:16px; margin-bottom:12px; }
.bench h2 { font-size:12px; color:#8844FF; margin-bottom:12px; }
.row { display:flex; justify-content:space-between; padding:4px 0; border-bottom:1px solid #0d0d0d; font-size:11px; }
.row .k { color:#555; }
.row .v { color:#f0f0f0; }
.winner { color:#00FF88; font-weight:700; }
.loser { color:#555; }
button { background:linear-gradient(90deg,#FF6B2B,#FF2255,#8844FF); border:none; color:#fff; padding:10px 24px; font-family:inherit; font-size:12px; cursor:pointer; margin-bottom:16px; }
button:hover { opacity:0.9; }
#log { background:#050505; border:1px solid #141414; padding:12px; font-size:10px; color:#444; max-height:300px; overflow-y:auto; white-space:pre-wrap; }
.highlight { color:#8844FF; }
</style>
</head>
<body>
<h1>Pixel Memory Benchmark</h1>
<div class="sub">Binary (×4,096) vs Trinary (×531,441) — BlackRoad OS · Z:=yx−w</div>
<div class="grid">
<div class="card binary">
<h2>Binary Pixel (2^12)</h2>
<div class="metric"><div class="label">Multiplier</div><div class="value">×4,096</div></div>
<div class="metric"><div class="label">3.3 TB Physical →</div><div class="value" id="bin-logical">13.5 PB</div></div>
<div class="metric"><div class="label">Address Width</div><div class="value">48-bit</div></div>
<div class="metric"><div class="label">Block Size</div><div class="value">4 KB</div></div>
</div>
<div class="card trinary">
<h2>Trinary Pixel (3^12)</h2>
<div class="metric"><div class="label">Multiplier</div><div class="value">×531,441</div></div>
<div class="metric"><div class="label">3.3 TB Physical →</div><div class="value" id="tri-logical">1,753.8 PB</div></div>
<div class="metric"><div class="label">Address Width</div><div class="value">24-trit</div></div>
<div class="metric"><div class="label">Block Size</div><div class="value">519 KB</div></div>
</div>
</div>
<button onclick="runBenchmark()">▸ Run Speed Benchmark (1M ops)</button>
<div class="bench" id="results" style="display:none">
<h2>Speed Results</h2>
<div id="bench-rows"></div>
</div>
<div class="bench">
<h2>Address Space Comparison (per node)</h2>
<div id="space-rows"></div>
</div>
<div class="bench">
<h2>Trinary Tier Cascade (powers of 3)</h2>
<div id="tier-rows"></div>
</div>
<h2 style="font-size:12px; color:#555; margin:16px 0 8px">Live Output</h2>
<div id="log"></div>
<script type="module">
// ─── Binary encoding ────────────────────────────────────────────
function encodePixelAddress(tier, node, block) {
const t = (tier & 0xF).toString(16);
const n = (node & 0xF).toString(16);
const b = block.toString(16).padStart(10, '0');
return `px:${t}${n}${b}`;
}
function decodePixelAddress(addr) {
const hex = addr.slice(3);
return {
tier: parseInt(hex[0], 16),
node: parseInt(hex[1], 16),
block: parseInt(hex.slice(2), 16),
};
}
// ─── Trinary encoding ───────────────────────────────────────────
function toTernary(n) {
if (n === 0) return '0';
const trits = [];
let v = n;
while (v > 0) { trits.push(v % 3); v = Math.floor(v / 3); }
return trits.reverse().join('');
}
function fromTernary(str) {
let v = 0;
for (const c of str) v = v * 3 + parseInt(c);
return v;
}
function encodeTriAddress(tier, node, block) {
const t = toTernary(tier).padStart(2, '0');
const n = toTernary(node).padStart(2, '0');
const b = toTernary(block).padStart(20, '0');
return `tx:${t}${n}${b}`;
}
function decodeTriAddress(addr) {
const tri = addr.slice(3);
return {
tier: fromTernary(tri.slice(0, 2)),
node: fromTernary(tri.slice(2, 4)),
block: fromTernary(tri.slice(4)),
};
}
// ─── Balanced ternary ───────────────────────────────────────────
function toBalancedTernary(n) {
if (n === 0) return '0';
const trits = [];
let v = Math.abs(n);
while (v > 0) {
let r = v % 3; v = Math.floor(v / 3);
if (r === 2) { r = -1; v += 1; }
trits.push(r);
}
if (n < 0) trits.forEach((t, i) => trits[i] = -t);
return trits.reverse().map(t => t === -1 ? 'T' : t === 0 ? '0' : '1').join('');
}
// ─── Hashing ────────────────────────────────────────────────────
async function binaryHash(data) {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(data));
return Array.from(new Uint8Array(buf).slice(0, 6)).map(b => b.toString(16).padStart(2, '0')).join('');
}
async function trinaryHash(data) {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(data));
const arr = new Uint8Array(buf);
let num = BigInt(0);
for (let i = 0; i < 8; i++) num = (num << BigInt(8)) | BigInt(arr[i]);
const trits = [];
for (let i = 0; i < 40; i++) { trits.push(Number(num % BigInt(3))); num = num / BigInt(3); }
return trits.reverse().join('');
}
// ─── Logging ────────────────────────────────────────────────────
const log = document.getElementById('log');
function emit(msg) { log.textContent += msg + '\n'; log.scrollTop = log.scrollHeight; }
// ─── Populate static tables ─────────────────────────────────────
const NODES = [
{ name: 'Pico W ×2', gb: 0.004 },
{ name: 'Alice', gb: 16 },
{ name: 'Aria', gb: 32 },
{ name: 'Anastasia', gb: 25 },
{ name: 'Cecilia', gb: 128 },
{ name: 'Gematria', gb: 80 },
{ name: 'Octavia', gb: 1000 },
{ name: 'Google Drive', gb: 2048 },
];
function fmt(gb) {
if (gb >= 1e9) return (gb/1e9).toFixed(1) + ' EB';
if (gb >= 1e6) return (gb/1e6).toFixed(1) + ' PB';
if (gb >= 1e3) return (gb/1e3).toFixed(1) + ' TB';
return gb.toFixed(0) + ' GB';
}
// Space comparison
const spaceEl = document.getElementById('space-rows');
NODES.forEach(n => {
const binL = n.gb * 4096;
const triL = n.gb * 531441;
spaceEl.innerHTML += `<div class="row"><span class="k">${n.name} (${n.gb}GB)</span><span class="v" style="color:#4488FF">${fmt(binL)}</span><span class="v" style="color:#FF6B2B">${fmt(triL)}</span></div>`;
});
const totalPhys = NODES.reduce((s,n) => s + n.gb, 0);
spaceEl.innerHTML += `<div class="row" style="border-top:1px solid #222;margin-top:4px;padding-top:8px"><span class="k" style="color:#f0f0f0">TOTAL (${fmt(totalPhys)})</span><span class="v" style="color:#4488FF;font-weight:700">${fmt(totalPhys * 4096)}</span><span class="v" style="color:#FF6B2B;font-weight:700">${fmt(totalPhys * 531441)}</span></div>`;
// Trinary tiers
const tierEl = document.getElementById('tier-rows');
for (let i = 0; i <= 12; i++) {
const binVal = Math.pow(2, i);
const triVal = Math.pow(3, i);
tierEl.innerHTML += `<div class="row"><span class="k">Level ${i}</span><span class="v" style="color:#4488FF">2^${i} = ${binVal.toLocaleString()}</span><span class="v" style="color:#FF6B2B">3^${i} = ${triVal.toLocaleString()}</span></div>`;
}
// ─── Benchmark ──────────────────────────────────────────────────
const OPS = 1_000_000;
window.runBenchmark = async function() {
const resultsEl = document.getElementById('results');
const rowsEl = document.getElementById('bench-rows');
resultsEl.style.display = 'block';
rowsEl.innerHTML = '<div style="color:#555">Running...</div>';
emit('═══════════════════════════════════════════');
emit(' PIXEL MEMORY BENCHMARK — 1M operations');
emit('═══════════════════════════════════════════');
emit('');
const results = [];
// 1. Address encode speed
emit('▸ Address encoding (1M ops)...');
let t0 = performance.now();
for (let i = 0; i < OPS; i++) encodePixelAddress(i % 12, i % 8, i);
const binEncode = performance.now() - t0;
t0 = performance.now();
for (let i = 0; i < OPS; i++) encodeTriAddress(i % 12, i % 8, i);
const triEncode = performance.now() - t0;
results.push({ name: 'Encode address', bin: binEncode, tri: triEncode });
emit(` Binary: ${binEncode.toFixed(1)}ms`);
emit(` Trinary: ${triEncode.toFixed(1)}ms`);
emit('');
// 2. Address decode speed
emit('▸ Address decoding (1M ops)...');
const binAddrs = []; const triAddrs = [];
for (let i = 0; i < 1000; i++) {
binAddrs.push(encodePixelAddress(i % 12, i % 8, i * 1000));
triAddrs.push(encodeTriAddress(i % 12, i % 8, i * 1000));
}
t0 = performance.now();
for (let i = 0; i < OPS; i++) decodePixelAddress(binAddrs[i % 1000]);
const binDecode = performance.now() - t0;
t0 = performance.now();
for (let i = 0; i < OPS; i++) decodeTriAddress(triAddrs[i % 1000]);
const triDecode = performance.now() - t0;
results.push({ name: 'Decode address', bin: binDecode, tri: triDecode });
emit(` Binary: ${binDecode.toFixed(1)}ms`);
emit(` Trinary: ${triDecode.toFixed(1)}ms`);
emit('');
// 3. Base conversion speed
emit('▸ Base conversion (1M ops)...');
t0 = performance.now();
for (let i = 0; i < OPS; i++) i.toString(16);
const binConv = performance.now() - t0;
t0 = performance.now();
for (let i = 0; i < OPS; i++) toTernary(i);
const triConv = performance.now() - t0;
results.push({ name: 'Base conversion', bin: binConv, tri: triConv });
emit(` Binary (hex): ${binConv.toFixed(1)}ms`);
emit(` Trinary: ${triConv.toFixed(1)}ms`);
emit('');
// 4. Balanced ternary
emit('▸ Balanced ternary encode (1M ops)...');
t0 = performance.now();
for (let i = 0; i < OPS; i++) toBalancedTernary(i - 500000);
const balTri = performance.now() - t0;
results.push({ name: 'Balanced ternary', bin: binConv, tri: balTri });
emit(` Balanced: ${balTri.toFixed(1)}ms`);
emit('');
// 5. Hash speed (10K ops — crypto is expensive)
const HASH_OPS = 10_000;
emit(`▸ Content hash (${HASH_OPS.toLocaleString()} ops)...`);
t0 = performance.now();
for (let i = 0; i < HASH_OPS; i++) await binaryHash(`block-${i}`);
const binHash = performance.now() - t0;
t0 = performance.now();
for (let i = 0; i < HASH_OPS; i++) await trinaryHash(`block-${i}`);
const triHash = performance.now() - t0;
results.push({ name: `Hash (${HASH_OPS/1000}K ops)`, bin: binHash, tri: triHash });
emit(` Binary hash: ${binHash.toFixed(1)}ms (${(HASH_OPS/(binHash/1000)).toFixed(0)} ops/s)`);
emit(` Trinary hash: ${triHash.toFixed(1)}ms (${(HASH_OPS/(triHash/1000)).toFixed(0)} ops/s)`);
emit('');
// 6. Density metric
const densityRatio = 531441 / 4096;
emit('═══════════════════════════════════════════');
emit(` DENSITY: Trinary is ${densityRatio.toFixed(1)}× denser`);
emit(` Binary: 3.3 TB → ${fmt(3329.004 * 4096)}`);
emit(` Trinary: 3.3 TB → ${fmt(3329.004 * 531441)}`);
emit('═══════════════════════════════════════════');
// Render results table
rowsEl.innerHTML = '';
results.forEach(r => {
const binWin = r.bin <= r.tri;
const speedup = binWin ? (r.tri / r.bin).toFixed(1) : (r.bin / r.tri).toFixed(1);
rowsEl.innerHTML += `<div class="row">
<span class="k">${r.name}</span>
<span class="${binWin ? 'winner' : 'loser'}">${r.bin.toFixed(1)}ms</span>
<span class="${!binWin ? 'winner' : 'loser'}">${r.tri.toFixed(1)}ms</span>
<span class="v">${binWin ? 'Binary' : 'Trinary'} ${speedup}× faster</span>
</div>`;
});
rowsEl.innerHTML += `<div class="row" style="border-top:1px solid #222;margin-top:8px;padding-top:8px">
<span class="k" style="color:#f0f0f0">Address density</span>
<span style="color:#4488FF">×4,096</span>
<span style="color:#FF6B2B;font-weight:700">×531,441</span>
<span class="winner">Trinary 129.7× denser</span>
</div>`;
};
emit('BlackRoad OS — Pixel Memory Benchmark loaded');
emit('Binary (2^12 = 4,096) vs Trinary (3^12 = 531,441)');
emit('');
emit('Click "Run Speed Benchmark" to start...');
</script>
</body>
</html>