Skip to content

satisfactory-dev/benchmark.js

 
 

Repository files navigation

Satisfactory.dev Benchmark.js Fork

Coverage Status Workflow Status

Forked from benchmark.js

Documentation

In a browser:

<script src="benchmark.js"></script>

In an AMD loader:

require({
  'paths': {
    'benchmark': 'path/to/benchmark',
  }
},
['benchmark'], function(Benchmark) {/*…*/});

Using npm:

$ npm i --save benchmark

In Node.js:

var Benchmark = require('benchmark');

Optionally, use the microtime module by Wade Simmons:

npm i --save microtime
var Benchmark = require('benchmark');
function microtime() {
	try {
		const result = require('microtime');

		console.log('using microtime');

		return result;
	} catch {
	}

	console.log('not using microtime');

	return undefined;
}

const maybe_microtime = microtime();

if (maybe_microtime) {
	Benchmark = Benchmark.runInContext(
		undefined,
		maybe_microtime,
	);
}

Usage example:

var suite = new Benchmark.Suite;

// add tests
suite.add('RegExp#test', function() {
  /o/.test('Hello World!');
})
.add('String#indexOf', function() {
  'Hello World!'.indexOf('o') > -1;
})
// add listeners
.on('cycle', function(event) {
  console.log(String(event.target));
})
.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });

// logs:
// => RegExp#test x 4,161,532 +-0.99% (59 cycles)
// => String#indexOf x 6,139,623 +-1.00% (131 cycles)
// => Fastest is String#indexOf

Support

Tested in Tested in Chromium (143.0.7499.4), Firefox (144.0.2), WebKit (26.0), Node (20-25)

About

A benchmarking library. As used on jsPerf.com.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 86.1%
  • HTML 7.8%
  • CSS 5.0%
  • Makefile 1.1%