Files
Matt Hess 733ecd2681 Migrate all JS tests to Rust: 9-crate workspace, 703 tests, 0 JS remaining
Add root Cargo workspace with 9 crates: salvium-crypto (extended),
  salvium-types, salvium-consensus, salvium-wallet, salvium-tx,
  salvium-rpc, salvium-miner (extended), salvium-cli, salvium-multisig.

  New modules: chain_state, block_weight, alt_chain, validation,
  offline signing, stake lifecycle, wallet sync/query/encryption/utxo,
  randomx utilities, and full multisig crate with CARROT support.

  Delete 188 JS test/helper/debug files; archive integration test
  scripts to test/legacy-js/ for live testnet use. Testnet integration
  tests (transfer, stake, burn, convert, sweep) remain as #[ignore]-
  gated Rust tests runnable with --ignored against a live daemon.
2026-02-17 23:09:35 +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);