Skip to content

Commit

Permalink
Merge pull request #15 from fanatid/travis-and-benchmark
Browse files Browse the repository at this point in the history
Travis and benchmark
  • Loading branch information
dcousens committed Jan 25, 2016
2 parents 4819ddb + f3d2fb1 commit 9a2d222
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

17 changes: 11 additions & 6 deletions .travis.yml
@@ -1,10 +1,15 @@
sudo: false
language: node_js
before_install:
- "npm install npm -g"
node_js:
- "0.10"
- "0.12"
- "iojs"
- "4"
- "5"
env:
- TEST_SUITE=standard
- TEST_SUITE=unit
script: "npm run-script $TEST_SUITE"
matrix:
- TEST_SUITE=unit
matrix:
include:
- node_js: "4"
env: TEST_SUITE=standard
script: npm run $TEST_SUITE
63 changes: 63 additions & 0 deletions benchmark/benchmark.js
@@ -0,0 +1,63 @@
'use strict'

var crypto = require('crypto')
var benchmark = require('benchmark')

var baseX = require('../')
var bs58 = baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz')

var fixtureIndex = 0
var resetFixtureIndex = function () { fixtureIndex = 0 }
var fixtures = new Array(10000)
var getNextFixture = function () {
var fixture = fixtures[fixtureIndex++]
if (fixtureIndex === fixtures.length) {
fixtureIndex = 0
}

return fixture
}

var seed = process.env.SEED || crypto.randomBytes(32).toString('hex')
console.log('Seed: ' + seed)
for (var i = 0; i < fixtures.length; ++i) {
seed = crypto.createHash('sha256').update(seed).digest()

fixtures[i] = {
source: seed,
result: bs58.encode(seed)
}
}

if (/fast/i.test(process.argv[2])) {
console.log('Running in fast mode...')
benchmark.options.minTime = 0.3
benchmark.options.maxTime = 1
benchmark.options.minSamples = 3
} else {
benchmark.options.minTime = 1
}

new benchmark.Suite({
onStart: function () {
console.log('--------------------------------------------------')
},
onCycle: function (event) {
console.log(String(event.target))
},
onError: function (event) {
console.error(event.target.error)
},
onComplete: function () {
console.log('==================================================')
}
})
.add('encode', function () {
var fixture = getNextFixture()
bs58.encode(fixture.source)
}, {onStart: resetFixtureIndex, onCycle: resetFixtureIndex})
.add('decode', function () {
var fixture = getNextFixture()
bs58.decode(fixture.result)
}, {onStart: resetFixtureIndex, onCycle: resetFixtureIndex})
.run()
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -30,7 +30,12 @@
],
"author": "Daniel Cousens",
"license": "MIT",
"files": [
"index.js",
"README.md"
],
"devDependencies": {
"benchmark": "^2.0.0",
"mocha": "*",
"standard": "*"
}
Expand Down

0 comments on commit 9a2d222

Please sign in to comment.