Files
Hashpass-lib/benchmarks/sha256.ts
2025-08-16 16:11:33 +10:00

26 lines
660 B
TypeScript

import { sha256, binToBase58 } from '@bitauth/libauth';
const data = 'Hello, world!';
const count = 1_000_000;
let bytes = new TextEncoder().encode(data);
const start = performance.now();
for (let i = 0; i < count; i++) {
bytes = new Uint8Array(sha256.hash(bytes));
}
const end = performance.now();
const totalTimeMs = end - start;
const operationsPerSecond = (count / totalTimeMs) * 1000;
console.log(
`libauth sha256 per second: ${operationsPerSecond} (Total time: ${totalTimeMs}ms)`,
);
console.log(binToBase58(bytes));
if (binToBase58(bytes) !== '2YZjvhWqVKZgQFDnVkadwRcpJkqW6oNjiHPXxkEpq2zP') {
throw new Error('sha256 hash is incorrect');
}