Skip to content

lotress/js-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javascript Benchmarks


What's this?

A collection of some javascript benchmarks.

Requirements

  • Broswer with ES7 support or Node.js >= v8.0, Node.js >= v10.7 recommended

  • CoffeeScript >= v2.3

  • Timer in Node.js is more precise than broswers due to security concerns.

Install

git clone https://github.com/lotress/js-benchmark.git

Usage

Run tests under test folder.

coffee ./test/<test name>.coffee

A benchmark framework is included as bench.js.

import bench from './bench'

const N = 1e6
var arr = Array.from({ length: N }, (_, i) => i)
const p = () => {
  // do something each sample before all cases
}

const case1 = () => arr.slice(0) // do some heavy computing

const case2 = () => [...arr]

bench.setPrepare(p)
.addCase("Array slice", case1)
.addCase("Array splat", case2)
.run(100) // Run each case 100 times, then print results to console, returns bench itself
/*
Bench Array slice:
        average time:   4.247ms ±19.910%       fastest
Bench Array splat:
        average time:   31.657ms        ±9.583%        slowest
*/

About

A collection of some javascript benchmarks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published