bench: poly1305.

This commit is contained in:
Christopher Jeffrey 2016-08-01 01:54:12 -07:00
parent d86c439017
commit dfdee526db
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -3,6 +3,8 @@
var chachapoly = require('../lib/bcoin/chachapoly');
var bench = require('./bench');
console.log('note: rate measured in kb/s');
var chacha = new chachapoly.ChaCha20();
var iv = new Buffer('0102030405060708', 'hex');
chacha.init(iv, 0);
@ -12,4 +14,32 @@ for (var i = 0; i < 32; i++)
var end = bench('encrypt');
for (var i = 0; i < 1000000; i++)
chacha.encrypt(data);
end(i);
end(i * 32 / 1024);
var poly = new chachapoly.Poly1305();
var key = new Buffer('000102030405060708090a0b0c0d0e0f', 'hex');
poly.init(key);
var data = new Buffer(32);
for (var i = 0; i < 32; i++)
data[i] = i & 0xff;
var end = bench('update');
for (var i = 0; i < 1000000; i++)
poly.update(data);
end(i * 32 / 1024);
var end = bench('finish');
for (var i = 0; i < 1000000; i++) {
poly.init(key);
poly.update(data);
poly.finish();
}
end(i * 32 / 1024);
// For reference:
var utils = require('../lib/bcoin/utils');
var end = bench('sha256');
for (var i = 0; i < 1000000; i++)
utils.hash256(data);
end(i * 32 / 1024);