Skip to content

Instantly share code, notes, and snippets.

@monken
Created March 9, 2021 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monken/7ee463e6a1ed1582615ff1ada5e8628d to your computer and use it in GitHub Desktop.
Save monken/7ee463e6a1ed1582615ff1ada5e8628d to your computer and use it in GitHub Desktop.
import * as crypto from 'crypto';
const key = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
});
const input = crypto.randomBytes(128);
function run(iterations) {
for (let i = 0; i < iterations; i++) {
crypto.createSign('RSA-SHA256').update(input).sign(key.privateKey);
}
}
const start = process.hrtime.bigint();
run(1000);
const end = process.hrtime.bigint();
console.log(`took ${Number(end - start)/1000000} ms`);
# ami-0f10e11691c9ab660 (us-east-2) on a c6g.large
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
source .nvm/nvm.sh
nvm install 15
# compiling node 15 from source did not make a difference
# same results with NodeJS 14
node benchmark.mjs
# output on a c6g.large
# took 3411.936128 ms
# output on a c5.large
# took 606.871429 ms
# output on a M1 Apple MacBook Pro
# took 577.953708 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment