nano-benchmark 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/bin/nano-bench.js +7 -1
- package/bin/nano-watch.js +7 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,8 +36,23 @@ npm install --save nano-benchmark
|
|
|
36
36
|
|
|
37
37
|
Both [deno](https://deno.land/) and [bun](https://bun.sh/) are supported.
|
|
38
38
|
|
|
39
|
+
If you want to run the benchmark in Deno, Bun, etc. you can specify `self` as the `file` argument.
|
|
40
|
+
In this case the utility will print out its file name to `stdout` and exit. It allows running
|
|
41
|
+
the utility with alternative JavaScript interpreters.
|
|
42
|
+
|
|
43
|
+
Examples with `bash`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
$ npx nano-bench benchmark.js
|
|
47
|
+
$ bun `npx nano-bench self` benchmark.js
|
|
48
|
+
$ deno run --allow-read --allow-hrtime `npx nano-bench self` benchmark.js
|
|
49
|
+
$ deno run -A `npx nano-bench self` benchmark.js
|
|
50
|
+
$ node `npx nano-bench self` benchmark.js
|
|
51
|
+
```
|
|
52
|
+
|
|
39
53
|
Don't forget to specify the appropriate permissions for Deno to run the benchmark scripts:
|
|
40
|
-
`--allow-read` (required) and `--allow-hrtime` (optional but recommended).
|
|
54
|
+
`--allow-read` (required) and `--allow-hrtime` (optional but recommended). Or consider using
|
|
55
|
+
`-A` or `--allow-all` to allow all permissions (used it only in safe environments!).
|
|
41
56
|
|
|
42
57
|
## Documentation
|
|
43
58
|
|
|
@@ -96,4 +111,5 @@ BSD 3-Clause License
|
|
|
96
111
|
|
|
97
112
|
## Release history
|
|
98
113
|
|
|
114
|
+
- 1.0.1: *Added "self" argument to utilities so it can be used with Deno, Bun, etc.*
|
|
99
115
|
- 1.0.0: *Initial release.*
|
package/bin/nano-bench.js
CHANGED
|
@@ -33,7 +33,7 @@ program
|
|
|
33
33
|
.name('nano-bench')
|
|
34
34
|
.description('Small utility to benchmark and compare code.')
|
|
35
35
|
.version('1.0.0')
|
|
36
|
-
.argument('<file>', 'File to benchmark')
|
|
36
|
+
.argument('<file>', 'File to benchmark.\nIf "self", returns its file name to stdout and exits.')
|
|
37
37
|
.option('-m, --ms <ms>', 'measurement time in milliseconds', toInt, 50)
|
|
38
38
|
.addOption(
|
|
39
39
|
new Option('-i, --iterations <iterations>', 'measurement iterations (overrides --ms)')
|
|
@@ -53,6 +53,12 @@ program.parse();
|
|
|
53
53
|
const options = program.opts(),
|
|
54
54
|
args = program.args;
|
|
55
55
|
|
|
56
|
+
if (args[0] === 'self') {
|
|
57
|
+
const name = String(import.meta.url);
|
|
58
|
+
console.log(name.startsWith('file://') ? name.slice(7) : name);
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
56
62
|
// validate the options
|
|
57
63
|
|
|
58
64
|
if (options.minIterations < 1) program.error('The minimum number of iterations must be >= 1');
|
package/bin/nano-watch.js
CHANGED
|
@@ -28,7 +28,7 @@ program
|
|
|
28
28
|
.name('nano-watch')
|
|
29
29
|
.description('Small utility to continuously benchmark code.')
|
|
30
30
|
.version('1.0.0')
|
|
31
|
-
.argument('<file>', 'File to benchmark')
|
|
31
|
+
.argument('<file>', 'File to benchmark.\nIf "self", returns its file name to stdout and exits.')
|
|
32
32
|
.argument('[method]', 'Method name to benchmark')
|
|
33
33
|
.option('-m, --ms <ms>', 'milliseconds per iteration', value => parseInt(value), 500)
|
|
34
34
|
.option('-i, --iterations <number>', 'number of iterations (default: Infinity)', value =>
|
|
@@ -42,6 +42,12 @@ program.parse();
|
|
|
42
42
|
const options = program.opts(),
|
|
43
43
|
args = program.args;
|
|
44
44
|
|
|
45
|
+
if (args[0] === 'self') {
|
|
46
|
+
const name = String(import.meta.url);
|
|
47
|
+
console.log(name.startsWith('file://') ? name.slice(7) : name);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
const fileName = new URL(args[0], `file://${process.cwd()}/`);
|
|
46
52
|
|
|
47
53
|
let fn;
|