Skip to content

Commit 0cf9c99

Browse files
committed
Add environment check and add browser benchmarks
1 parent b00b60c commit 0cf9c99

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var bench = require( '@stdlib/bench' );
6+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
7+
var pkg = require( './../package.json' ).name;
8+
var cwd = require( './../lib/browser.js' );
9+
10+
11+
// MAIN //
12+
13+
bench( pkg, function benchmark( b ) {
14+
var dir;
15+
var i;
16+
17+
b.tic();
18+
for ( i = 0; i < b.iterations; i++ ) {
19+
// Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear.
20+
dir = cwd();
21+
if ( !isString( dir ) ) {
22+
b.fail( 'should return a string' );
23+
}
24+
}
25+
b.toc();
26+
if ( !isString( dir ) ) {
27+
b.fail( 'should return a string' );
28+
}
29+
b.pass( 'benchmark finished' );
30+
b.end();
31+
});

lib/node_modules/@stdlib/process/cwd/benchmark/benchmark.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44

55
var bench = require( '@stdlib/bench' );
66
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
7+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
78
var pkg = require( './../package.json' ).name;
89
var cwd = require( './../lib' );
910

1011

12+
// VARIABLES //
13+
14+
var opts = {
15+
'skip': IS_BROWSER
16+
};
17+
18+
1119
// MAIN //
1220

13-
bench( pkg, function benchmark( b ) {
21+
bench( pkg, opts, function benchmark( b ) {
1422
var dir;
1523
var i;
1624

0 commit comments

Comments
 (0)