Socket
Socket
Sign inDemoInstall

nanobench

Package Overview
Dependencies
3
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 2.0.0

parse.js

52

index.js
var mutexify = require('mutexify')
var prettyHrtime = require('pretty-hrtime')
var proc = require('child_process')
var path = require('path')
var lock = mutexify()

@@ -27,6 +29,11 @@ var one = false

if (runs === 0) {
console.log('NANOBENCH version 1\n')
lock(function (release) {
gitHash(function (_, hash) {
console.log('NANOBENCH version 2\n> ' + command(hash) + '\n')
release()
})
})
}
runs++
lock(function (release) {

@@ -44,7 +51,13 @@ console.log('# ' + name)

cur = null
console.log(' fail ' + err.message)
console.log('fail ' + err.message + '\n')
release()
}
b.end = function () {
b.log = function (msg) {
}
b.end = function (msg) {
if (msg) b.log(msg)
cur = null

@@ -60,3 +73,3 @@ var time = process.hrtime(begin)

console.log(' end ~' + prettyHrtime(time) + ' ' + rawTime(time))
console.log('ok ~' + prettyHrtime(time) + ' ' + rawTime(time) + '\n')
release()

@@ -73,6 +86,31 @@ }

cur.error(new Error('bench was never ended'))
console.log('\n# fail\n')
console.log('fail\n')
return
}
console.log('\n# total ~' + prettyHrtime(total) + ' ' + rawTime(total) + '\n\n# ok\n')
console.log('ok ~' + prettyHrtime(total) + ' ' + rawTime(total) + '\n')
})
function command (hash) {
var argv = process.argv.slice(0)
if (argv[0] === '/usr/local/bin/node') argv[0] = 'node'
if (argv[1] === path.join(__dirname, 'run.js')) {
argv.shift()
argv[0] = 'nanobench'
}
argv = argv.map(function (name) {
var cwd = process.cwd() + path.sep
return name.indexOf(cwd) === 0 ? name.slice(cwd.length) : name
})
return (hash ? 'git checkout ' + hash + ' && ' : '') + argv.join(' ')
}
function gitHash (cb) {
proc.exec("git log --pretty=format:'%h' -n 1", function (err, stdout) {
if (err) return cb(null, null)
var hash = stdout.trim()
if (!/[0-9a-f]/.test(hash)) return cb(null, null)
cb(null, hash)
})
}

2

package.json
{
"name": "nanobench",
"version": "1.0.3",
"version": "2.0.0",
"description": "Simple benchmarking tool with TAP-like output that is easy to parse",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -57,14 +57,15 @@ # nanobench

```
NANOBENCH version 1
NANOBENCH version 2
> git checkout 7369272 && node example.js
# sha256 200.000 times
end ~568 ms (0 s + 568372106 ns)
ok ~664 ms (0 s + 663775913 ns)
# sha1 200.000 times
end ~550 ms (0 s + 550049856 ns)
ok ~564 ms (0 s + 563784403 ns)
# sha256 200.000 times
end ~591 ms (0 s + 591365175 ns)
ok ~575 ms (0 s + 575039783 ns)
# total ~1.71 s (1 s + 709787137 ns)
# ok
ok ~1.8 s (1 s + 802600099 ns)
```

@@ -81,2 +82,3 @@

* `b.error(err)` - Benchmark failed. Report error.
* `b.log(msg)` - Log out a message

@@ -93,4 +95,3 @@ #### `benchmark.skip(name, run)`

If you have multiple benchmarks as different files you can use the cli benchmark runner
to run them all
If you have multiple benchmarks as different files you can use the cli benchmark runner to run them all

@@ -102,4 +103,37 @@ ```

## Parser
An parser for the output format is included as well. You can require it from node using
``` js
var parse = require('nanobench/parse')
var output = parse(outputAsString)
console.log(output)
```
If you parse the above example output an object similar to this will be printed out
``` js
{ type: 'NANOBENCH',
version: 2,
command: 'git checkout 7369272 && nanobench example.js',
benchmarks:
[ { name: 'sha256 200.000 times',
output: [],
error: null,
time: [Object] },
{ name: 'sha1 200.000 times',
output: [],
error: null,
time: [Object] },
{ name: 'sha256 200.000 times',
output: [],
error: null,
time: [Object] } ],
error: null,
time: [ 1, 802600099 ] }
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc