packages/cryptobox/src/demo/benchmark.js
async function encryptBeforeDecrypt({alice, bob}, messageCount) {
  const numbers = numbersInArray(messageCount);

  // Encryption
  process.stdout.write(`Measuring encryption time for "${messageCount}" messages ... `);
  let startTime = process.hrtime();
  const encryptedMessages = await Promise.all(
    numbers.map(value => alice.encrypt(createSessionId(bob), `This is a long message with number ${value.toString()}`))
  );
  let stopTime = getTimeInSeconds(startTime);
  process.stdout.write('Done.\n');

  console.info(`Execution time: ${stopTime} seconds.\n`);

  // Decryption
  process.stdout.write(`Measuring decryption time for "${messageCount}" messages ... `);
  startTime = process.hrtime();
  await Promise.all(
    encryptedMessages.map(async encryptedMessage => await bob.decrypt(createSessionId(alice), encryptedMessage))
  );
  stopTime = getTimeInSeconds(startTime);
  process.stdout.write('Done.\n');

  console.info(`Execution time: ${stopTime} seconds.\n`);
}
async function encryptBeforeDecrypt({alice, bob}, messageCount) {
  const numbers = numbersInArray(messageCount);

  // Encryption
  process.stdout.write(`Measuring encryption time for "${messageCount}" messages ... `);
  let startTime = process.hrtime();
  const encryptedMessages = await Promise.all(
    numbers.map(value => alice.encrypt(createSessionId(bob), `This is a long message with number ${value.toString()}`))
  );
  let stopTime = getTimeInSeconds(startTime);
  process.stdout.write('Done.\n');

  console.info(`Execution time: ${stopTime} seconds.\n`);

  // Decryption
  process.stdout.write(`Measuring decryption time for "${messageCount}" messages ... `);
  startTime = process.hrtime();
  await Promise.all(
    encryptedMessages.map(async encryptedMessage => await bob.decrypt(createSessionId(alice), encryptedMessage))
  );
  stopTime = getTimeInSeconds(startTime);
  process.stdout.write('Done.\n');

  console.info(`Execution time: ${stopTime} seconds.\n`);
}
async function encryptBeforeDecrypt ( { alice , bob } , messageCount ) { const numbers = numbersInArray ( messageCount ) ; // Encryption process . stdout . write ( ` ${ messageCount } ` ) ; let startTime = process . hrtime ( ) ; const encryptedMessages = await Promise . all ( numbers . map ( value => alice . encrypt ( createSessionId ( bob ) , ` ${ value . toString ( ) } ` ) ) ) ; let stopTime = getTimeInSeconds ( startTime ) ; process . stdout . write ( 'Done.\n' ) ; console . info ( ` ${ stopTime } \n ` ) ; // Decryption process . stdout . write ( ` ${ messageCount } ` ) ; startTime = process . hrtime ( ) ; await Promise . all ( encryptedMessages . map ( async encryptedMessage => await bob . decrypt ( createSessionId ( alice ) , encryptedMessage ) ) ) ; stopTime = getTimeInSeconds ( startTime ) ; process . stdout . write ( 'Done.\n' ) ; console . info ( ` ${ stopTime } \n ` ) ; }
Runs the test scenario and measures times.
Runs the test scenario and measures times .