-
-
Save bnoordhuis/2cbc86de7719c37ba0d0 to your computer and use it in GitHub Desktop.
tls benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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