Skip to content
Permalink
Browse files

add benchsuite

  • Loading branch information...
dcousens committed May 19, 2017
1 parent e484d59 commit ce23f7eb38837063f6a33d5a7ab77b2d11965435
Showing with 48 additions and 0 deletions.
  1. +1 −0 .npmignore
  2. +32 −0 bench/index.js
  3. +15 −0 bench/package.json
@@ -1,2 +1,3 @@
bench/
scripts/
test/
@@ -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)
@@ -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"
}
}

0 comments on commit ce23f7e

Please sign in to comment.
You can’t perform that action at this time.