macaroons.js benchmark
January 9, 2015 ยท View on GitHub
// requires // $> npm install benchmark
var Benchmark = require('benchmark'); var suite = new Benchmark.Suite;
var MacaroonsBuilder = require('../index.js').MacaroonsBuilder; var MacaroonsVerifier = require('../index.js').MacaroonsVerifier;
var serialized1 = (function prepare_a_macaroon_for_deserialization_with_string() { var location = "http://www.example.org"; var secretKey = "this is our super secret key; only we should know it"; var identifier = "we used our secret key"; var macaroon = MacaroonsBuilder.create(location, secretKey, identifier); return macaroon.serialize(); })(); var serialized2 = (function prepare_a_macaroon_for_deserialization_with_Buffer() { var location = "http://www.example.org"; var secretKey = new Buffer("this is our super secret key; only we should know it", 'ascii'); var identifier = "we used our secret key"; var macaroon = MacaroonsBuilder.create(location, secretKey, identifier); return macaroon.serialize(); })();
function benchmark_Serialize_with_key_string() { var location = "http://www.example.org"; var secretKey = "this is our super secret key; only we should know it"; var identifier = "we used our secret key"; var macaroon = MacaroonsBuilder.create(location, secretKey, identifier); macaroon.serialize(); }
function benchmark_Serialize_with_key_Buffer() { var location = "http://www.example.org"; var secretKey = new Buffer("this is our super secret key; only we should know it", 'ascii'); var identifier = "we used our secret key"; var macaroon = MacaroonsBuilder.create(location, secretKey, identifier); macaroon.serialize(); }
function benchmark_DeSerialize_and_verify_with_key_string() { var secretKey = "this is our super secret key; only we should know it"; var macaroon = MacaroonsBuilder.deserialize(serialized1); new MacaroonsVerifier(macaroon).assertIsValid(secretKey); }
function benchmark_DeSerialize_and_verify_with_key_Buffer() { var secretKey = new Buffer("this is our super secret key; only we should know it",'ascii'); var macaroon = MacaroonsBuilder.deserialize(serialized2); new MacaroonsVerifier(macaroon).assertIsValid(secretKey); }
// add tests suite.add('macaroons.js benchmark') .add('serialize with secret string', benchmark_Serialize_with_key_string) .add('serialize with secret Buffer', benchmark_Serialize_with_key_Buffer) .add('de-serialize and verify with secret string', benchmark_DeSerialize_and_verify_with_key_string) .add('de-serialize and verify with secret Buffer', benchmark_DeSerialize_and_verify_with_key_Buffer) // add listeners .on('cycle', function (event) { console.log(String(event.target)); }) .on('complete', function () { console.log('Fastest is ' + this.filter('fastest').pluck('name')); }) // run async .run({'async': true});