Files
salvium-rs/test/test-randomx-timing.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

54 lines
1.7 KiB
JavaScript

/**
* Test RandomX Timing
*
* Measures initialization and hashing times separately.
*/
import { randomx_init_cache, randomx_create_vm } from '../src/randomx/vendor/index.js';
async function main() {
console.log('RandomX Timing Test');
console.log('===================\n');
// Measure cache initialization
console.log('1. Cache initialization (256MB)...');
const seedHash = new TextEncoder().encode('test seed hash');
const cacheStart = Date.now();
const cache = randomx_init_cache(seedHash);
const cacheTime = Date.now() - cacheStart;
console.log(` Cache init time: ${(cacheTime / 1000).toFixed(2)}s\n`);
// Measure VM creation
console.log('2. VM creation...');
const vmStart = Date.now();
const vm = randomx_create_vm(cache);
const vmTime = Date.now() - vmStart;
console.log(` VM creation time: ${vmTime}ms\n`);
// Measure hashing
console.log('3. Hashing (10 hashes)...');
const template = new Uint8Array(76);
const view = new DataView(template.buffer);
const hashStart = Date.now();
for (let i = 0; i < 10; i++) {
view.setUint32(39, i, true);
const hash = vm.calculate_hash(template);
if (i === 0) {
const hashHex = Array.from(hash).map(b => b.toString(16).padStart(2, '0')).join('');
console.log(` First hash: ${hashHex.substring(0, 16)}...`);
}
}
const hashTime = Date.now() - hashStart;
const hps = 10 / (hashTime / 1000);
console.log(` 10 hashes in ${hashTime}ms (${hps.toFixed(2)} H/s)\n`);
console.log('Summary:');
console.log(` - Cache init: ${(cacheTime / 1000).toFixed(2)}s (one-time cost)`);
console.log(` - VM creation: ${vmTime}ms (one-time cost)`);
console.log(` - Hash rate: ~${hps.toFixed(1)} H/s`);
}
main().catch(console.error);