Files
salvium-rs/test/benchmark-randomx.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.4 KiB
JavaScript

/**
* RandomX Performance Benchmark
*/
import { RandomXContext } from '../src/randomx/index.js';
async function benchmark() {
console.log('RandomX Performance Benchmark');
console.log('=============================\n');
const ctx = new RandomXContext();
console.log('Initializing cache (256MB)...');
const initStart = Date.now();
await ctx.init(new Uint8Array(32)); // 32-byte key
const initTime = Date.now() - initStart;
console.log(`Cache init: ${initTime}ms\n`);
// Warm up
console.log('Warming up (10 hashes)...');
for (let i = 0; i < 10; i++) {
ctx.hash(`warmup ${i}`);
}
// Benchmark
const iterations = 100;
console.log(`\nBenchmarking ${iterations} hashes...`);
const hashes = [];
const start = Date.now();
for (let i = 0; i < iterations; i++) {
const hash = ctx.hashHex(`benchmark input ${i}`);
hashes.push(hash);
}
const elapsed = Date.now() - start;
const hashesPerSecond = (iterations / elapsed) * 1000;
console.log(`\nResults:`);
console.log(` Total time: ${elapsed}ms`);
console.log(` Hashes: ${iterations}`);
console.log(` Speed: ${hashesPerSecond.toFixed(2)} H/s`);
console.log(` Avg per hash: ${(elapsed / iterations).toFixed(2)}ms`);
// Show sample hashes
console.log(`\nSample hashes:`);
console.log(` [0]: ${hashes[0]}`);
console.log(` [1]: ${hashes[1]}`);
console.log(` [99]: ${hashes[99]}`);
}
benchmark().catch(console.error);