Get your own Node server
const crypto = require('crypto');
const { performance } = require('perf_hooks');

// Data to hash (1MB of random data)
const data = crypto.randomBytes(1024 * 1024);

// Function to measure hash algorithm performance
function measureHashPerformance(algorithm, iterations = 100) {
  // Ensure the algorithm is supported
  try {
    crypto.createHash(algorithm);
  } catch (error) {
    return { algorithm, error: error.message };
  }
  
  const startTime = performance.now();
  
  for (let i = 0; i < iterations; i++) {
    const hash = crypto.createHash(algorithm);
    hash.update(data);
    hash.digest();
  }
  
  const endTime = performance.now();
  const totalTime = endTime - startTime;
  
  return {
    algorithm,
    iterations,
    totalTimeMs: totalTime.toFixed(2),
    timePerHashMs: (totalTime / iterations).toFixed(4),
    hashesPerSecond: Math.floor(iterations / (totalTime / 1000))
  };
}

// Test various hash algorithms
const algorithms = ['md5', 'sha1', 'sha256', 'sha512', 'sha3-256', 'sha3-512'];
const results = [];

console.log('Measuring hash performance for 1MB of data...');

algorithms.forEach(algorithm => {
  results.push(measureHashPerformance(algorithm));
});

// Display results in a table format
console.table(results);

// Display relative performance (normalized to the fastest algorithm)
console.log('\nRelative Performance:');

// Find the fastest algorithm
const fastest = results.reduce((prev, current) => {
  if (current.error) return prev;
  return (prev && prev.hashesPerSecond > current.hashesPerSecond) ? prev : current;
}, null);

if (fastest) {
  results.forEach(result => {
    if (!result.error) {
      const relativeSpeed = (result.hashesPerSecond / fastest.hashesPerSecond).toFixed(2);
      console.log(`${result.algorithm}: ${relativeSpeed}x (${result.hashesPerSecond} hashes/sec)`);
    } else {
      console.log(`${result.algorithm}: Error - ${result.error}`);
    }
  });
}

              
Measuring hash performance for 1MB of data...
┌─────────┬────────────┬────────────┬───────────────┬──────────────────┬───────────────────┐
│ (index) │ algorithm  │ iterations │ totalTimeMs   │ timePerHashMs    │ hashesPerSecond   │
├─────────┼────────────┼────────────┼───────────────┼──────────────────┼───────────────────┤
│ 0       │ 'md5'      │ 100        │ '123.45'      │ '1.2345'         │ 810               │
│ 1       │ 'sha1'     │ 100        │ '145.67'      │ '1.4567'         │ 686               │
│ 2       │ 'sha256'   │ 100        │ '234.56'      │ '2.3456'         │ 426               │
│ 3       │ 'sha512'   │ 100        │ '345.67'      │ '3.4567'         │ 289               │
│ 4       │ 'sha3-256' │ 100        │ '456.78'      │ '4.5678'         │ 219               │
│ 5       │ 'sha3-512' │ 100        │ '567.89'      │ '5.6789'         │ 176               │
└─────────┴────────────┴────────────┴───────────────┴──────────────────┴───────────────────┘

Relative Performance:
md5: 1.00x (810 hashes/sec)
sha1: 0.85x (686 hashes/sec)
sha256: 0.53x (426 hashes/sec)
sha512: 0.36x (289 hashes/sec)
sha3-256: 0.27x (219 hashes/sec)
sha3-512: 0.22x (176 hashes/sec)