summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-05-17 13:04:02 -0700
committerisaacs <i@izs.me>2013-05-17 14:04:54 -0700
commit61c9f78c639459f28eea3d1de203b92debd9f513 (patch)
tree72e6860c814a59075d8d61c0e8fff458db7925e0 /benchmark
parent79988438078f58f828811ec87394700ccef42293 (diff)
parentf59ab10a6415e7dce7a6c3b6e734c213298ec205 (diff)
downloadnodejs-61c9f78c639459f28eea3d1de203b92debd9f513.tar.gz
nodejs-61c9f78c639459f28eea3d1de203b92debd9f513.tar.bz2
nodejs-61c9f78c639459f28eea3d1de203b92debd9f513.zip
Merge remote-tracking branch 'ry/v0.10' into master
Conflicts: AUTHORS ChangeLog deps/uv/ChangeLog deps/uv/config-unix.mk deps/uv/src/unix/stream.c deps/uv/src/version.c deps/uv/uv.gyp src/node.cc src/node_buffer.cc src/node_crypto.cc src/node_version.h src/stream_wrap.cc src/stream_wrap.h
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/crypto/cipher-stream.js4
-rw-r--r--benchmark/crypto/hash-stream-creation.js86
-rw-r--r--benchmark/crypto/hash-stream-throughput.js77
3 files changed, 164 insertions, 3 deletions
diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js
index 2a48a7e3f..4e8198931 100644
--- a/benchmark/crypto/cipher-stream.js
+++ b/benchmark/crypto/cipher-stream.js
@@ -16,8 +16,6 @@ function main(conf) {
api = 'legacy';
}
- var dur = conf.dur;
-
var crypto = require('crypto');
var assert = require('assert');
var alice = crypto.getDiffieHellman('modp5');
@@ -73,7 +71,7 @@ function streamWrite(alice, bob, message, encoding, writes) {
bob.on('end', function() {
// Gbits
var bits = written * 8;
- var gbits = written / (1024 * 1024 * 1024);
+ var gbits = bits / (1024 * 1024 * 1024);
bench.end(gbits);
});
diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js
new file mode 100644
index 000000000..a14aa2201
--- /dev/null
+++ b/benchmark/crypto/hash-stream-creation.js
@@ -0,0 +1,86 @@
+// throughput benchmark
+// creates a single hasher, then pushes a bunch of data through it
+var common = require('../common.js');
+var crypto = require('crypto');
+
+var bench = common.createBenchmark(main, {
+ writes: [500],
+ algo: [ 'sha256', 'md5' ],
+ type: ['asc', 'utf', 'buf'],
+ out: ['hex', 'binary', 'buffer'],
+ len: [2, 1024, 102400, 1024 * 1024],
+ api: ['legacy', 'stream']
+});
+
+function main(conf) {
+ var api = conf.api;
+ if (api === 'stream' && process.version.match(/^v0\.[0-8]\./)) {
+ console.error('Crypto streams not available until v0.10');
+ // use the legacy, just so that we can compare them.
+ api = 'legacy';
+ }
+
+ var crypto = require('crypto');
+ var assert = require('assert');
+
+ var message;
+ var encoding;
+ switch (conf.type) {
+ case 'asc':
+ message = new Array(conf.len + 1).join('a');
+ encoding = 'ascii';
+ break;
+ case 'utf':
+ message = new Array(conf.len / 2 + 1).join('ü');
+ encoding = 'utf8';
+ break;
+ case 'buf':
+ message = new Buffer(conf.len);
+ message.fill('b');
+ break;
+ default:
+ throw new Error('unknown message type: ' + conf.type);
+ }
+
+ var fn = api === 'stream' ? streamWrite : legacyWrite;
+
+ bench.start();
+ fn(conf.algo, message, encoding, conf.writes, conf.len, conf.out);
+}
+
+function legacyWrite(algo, message, encoding, writes, len, outEnc) {
+ var written = writes * len;
+ var bits = written * 8;
+ var gbits = bits / (1024 * 1024 * 1024);
+
+ while (writes-- > 0) {
+ var h = crypto.createHash(algo);
+ h.update(message, encoding);
+ var res = h.digest(outEnc);
+
+ // include buffer creation costs for older versions
+ if (outEnc === 'buffer' && typeof res === 'string')
+ res = new Buffer(res, 'binary');
+ }
+
+ bench.end(gbits);
+}
+
+function streamWrite(algo, message, encoding, writes, len, outEnc) {
+ var written = writes * len;
+ var bits = written * 8;
+ var gbits = bits / (1024 * 1024 * 1024);
+
+ while (writes-- > 0) {
+ var h = crypto.createHash(algo);
+
+ if (outEnc !== 'buffer')
+ h.setEncoding(outEnc);
+
+ h.write(message, encoding);
+ h.end();
+ h.read();
+ }
+
+ bench.end(gbits);
+}
diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js
new file mode 100644
index 000000000..62a8d45e1
--- /dev/null
+++ b/benchmark/crypto/hash-stream-throughput.js
@@ -0,0 +1,77 @@
+// throughput benchmark
+// creates a single hasher, then pushes a bunch of data through it
+var common = require('../common.js');
+var crypto = require('crypto');
+
+var bench = common.createBenchmark(main, {
+ writes: [500],
+ algo: [ 'sha256', 'md5' ],
+ type: ['asc', 'utf', 'buf'],
+ len: [2, 1024, 102400, 1024 * 1024],
+ api: ['legacy', 'stream']
+});
+
+function main(conf) {
+ var api = conf.api;
+ if (api === 'stream' && process.version.match(/^v0\.[0-8]\./)) {
+ console.error('Crypto streams not available until v0.10');
+ // use the legacy, just so that we can compare them.
+ api = 'legacy';
+ }
+
+ var crypto = require('crypto');
+ var assert = require('assert');
+
+ var message;
+ var encoding;
+ switch (conf.type) {
+ case 'asc':
+ message = new Array(conf.len + 1).join('a');
+ encoding = 'ascii';
+ break;
+ case 'utf':
+ message = new Array(conf.len / 2 + 1).join('ü');
+ encoding = 'utf8';
+ break;
+ case 'buf':
+ message = new Buffer(conf.len);
+ message.fill('b');
+ break;
+ default:
+ throw new Error('unknown message type: ' + conf.type);
+ }
+
+ var fn = api === 'stream' ? streamWrite : legacyWrite;
+
+ bench.start();
+ fn(conf.algo, message, encoding, conf.writes, conf.len);
+}
+
+function legacyWrite(algo, message, encoding, writes, len) {
+ var written = writes * len;
+ var bits = written * 8;
+ var gbits = bits / (1024 * 1024 * 1024);
+ var h = crypto.createHash(algo);
+
+ while (writes-- > 0)
+ h.update(message, encoding);
+
+ h.digest();
+
+ bench.end(gbits);
+}
+
+function streamWrite(algo, message, encoding, writes, len) {
+ var written = writes * len;
+ var bits = written * 8;
+ var gbits = bits / (1024 * 1024 * 1024);
+ var h = crypto.createHash(algo);
+
+ while (writes-- > 0)
+ h.write(message, encoding);
+
+ h.end();
+ h.read();
+
+ bench.end(gbits);
+}