Files
salvium-rs/test/debug-hash-quick.js
T
Matt Hess 7730b6993f ● Add AssemblyScript WASM VM for RandomX full mode
- Create assembly/vm.ts with full RandomX VM implementation
    - 256 instructions, 2048 iterations per hash
    - Native u64/f64 operations in WebAssembly
    - Full mode dataset lookups (2GB pre-computed)

  - Update miner to use WASM VM for full mode
    - mining-worker-asm.js uses pre-compiled WASM
    - ~32 H/s per thread (4x faster than light mode)
    - 8 threads achieves ~260 H/s

  - Clean up redundant code
    - Remove mining-worker-full.js (old JIT approach)
    - Consolidate 'asm' mode into 'full' mode
2026-01-18 01:16:10 +00:00

36 lines
1.2 KiB
JavaScript

/**
* Debug: Quick hash test with WASM cache
*/
import { RandomXContext, preloadWasm } from '../src/randomx/index.js';
console.log('=== Quick Hash Test ===\n');
// Pre-load WASM
console.log('Pre-loading WASM...');
await preloadWasm();
console.log('WASM loaded.\n');
const testKey = new TextEncoder().encode('test key 000');
const testInput = new TextEncoder().encode('This is a test');
const ctx = new RandomXContext({ wasm: true, fullMode: false });
console.log('Initializing cache (WASM)...');
const startInit = Date.now();
await ctx.init(testKey);
console.log(`Cache init: ${((Date.now() - startInit) / 1000).toFixed(1)}s\n`);
console.log('Computing hash...');
const startHash = Date.now();
const hash = ctx.hash(testInput);
const hashTime = (Date.now() - startHash) / 1000;
console.log(`Hash: ${Buffer.from(hash).toString('hex')}`);
console.log(`Expected: 639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f`);
console.log(`Time: ${hashTime.toFixed(2)}s`);
const expected = '639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f';
const actual = Buffer.from(hash).toString('hex');
console.log(`\nMatch: ${actual === expected ? 'YES!' : 'NO'}`);