Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis bnoordhuis/crypto-bench.js Secret
Created Oct 8, 2012

Embed
What would you like to do?
tls benchmark
var assert = require('assert');
var crypto = require('crypto');
var tls = require('tls');
var fs = require('fs');
var BUFFER_LENGTH = parseFloat(process.argv[2]);
var NUM_ITERATIONS = parseFloat(process.argv[3]);
assert(!isNaN(BUFFER_LENGTH), 'missing BUFFER_LENGTH');
assert(!isNaN(NUM_ITERATIONS), 'missing NUM_ITERATIONS');
var creds = crypto.createCredentials({
cert: fs.readFileSync(__dirname + '/../test/fixtures/test_cert.pem'),
key: fs.readFileSync(__dirname + '/../test/fixtures/test_key.pem')
});
var buf = new Buffer(BUFFER_LENGTH);
function pummel() {
var client = tls.createSecurePair(creds, false, false, false);
var server = tls.createSecurePair(creds, true, false, false);
client.on('secure', function() { client.cleartext.write(buf); });
server.on('secure', function() { server.cleartext.pipe(server.cleartext); });
server.encrypted.pipe(client.encrypted);
client.encrypted.pipe(server.encrypted);
}
for (var i = 0; i < NUM_ITERATIONS; ++i) pummel();
#!/bin/bash
NODE=$(dirname $0)/../out/Release/node
FILE=$(dirname $0)/crypto-bench.js
function bench {
echo "BENCH: $1 $2"
time $NODE $FILE $1 $2
echo
}
if [ ! -z "$*" ]; then
bench $*
else
# different buffer sizes but they all pump ~120 MB of data around
bench 125 1000000
bench 1000 125000
bench 5000 25000
bench 50000 2500
fi
BENCH: 125 1000000
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
real 0m48.378s
user 0m47.079s
sys 0m1.148s
BENCH: 1000 125000
real 1m59.335s
user 1m57.971s
sys 0m2.052s
BENCH: 5000 25000
real 0m27.728s
user 0m27.398s
sys 0m0.492s
BENCH: 50000 2500
real 0m7.067s
user 0m6.864s
sys 0m0.224s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.