[Pkg-javascript-commits] [node-browserify-aes] 13/43: add benchsuite

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 14:41:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-browserify-aes.

commit ce23f7eb38837063f6a33d5a7ab77b2d11965435
Author: Daniel Cousens <github at dcousens.com>
Date:   Fri May 19 13:37:38 2017 +1000

    add benchsuite
---
 .npmignore         |  1 +
 bench/index.js     | 32 ++++++++++++++++++++++++++++++++
 bench/package.json | 15 +++++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/.npmignore b/.npmignore
index f1f4eb0..2a625c5 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,2 +1,3 @@
+bench/
 scripts/
 test/
diff --git a/bench/index.js b/bench/index.js
new file mode 100644
index 0000000..172d3cc
--- /dev/null
+++ b/bench/index.js
@@ -0,0 +1,32 @@
+let Benchmark = require('benchmark')
+let _local = require('../browser')
+let _npm = require('browserify-aes/browser')
+let key = Buffer.alloc(16, 0xff)
+let iv = Buffer.alloc(16, 0x01)
+
+function test (mod, message) {
+  let cipher = mod.createCipheriv('aes-128-cbc', key, iv)
+  let b = cipher.update(message)
+  return Buffer.concat([b, cipher.final()])
+}
+
+let local = (m) => test(_local, m)
+let npm = (m) => test(_npm, m)
+
+function run (message) {
+  if (
+    local(message).toString('hex') !==
+    npm(message).toString('hex')
+  ) throw new Error('not equal')
+
+  new Benchmark.Suite()
+  .add('local', () => local(message))
+  .add('npm', () => npm(message))
+  .on('cycle', (e) => console.log(String(e.target)))
+  .run()
+}
+
+let lorem = Buffer.allocUnsafe(800)
+run(lorem.slice(0, 20), key)
+run(lorem.slice(0, 80), key)
+run(lorem, key)
diff --git a/bench/package.json b/bench/package.json
new file mode 100644
index 0000000..4b86052
--- /dev/null
+++ b/bench/package.json
@@ -0,0 +1,15 @@
+{
+  "name": "bench",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "benchmark": "^2.1.4",
+    "browserify-aes": "^1.0.6"
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-aes.git



More information about the Pkg-javascript-commits mailing list