UNPKG

639 BJavaScriptView Raw
1'use strict'
2const Benchmark = require('benchmark')
3const suite = new Benchmark.Suite
4
5let obj = process.env
6
7suite
8.add('for in', function() {
9 for(let i in obj) {
10 let o = obj[i]
11 }
12})
13.add('while --', function() {
14 let keys = Object.keys(obj)
15 let l = keys.length
16 while(l--) {
17 let o = obj[keys[l]]
18 }
19})
20.add('while shift', function() {
21 let keys = Object.keys(obj)
22 let k
23
24 while(k = keys.shift()) {
25 let o = obj[k]
26 }
27})
28.on('cycle', function(event) {
29 console.log(String(event.target))
30})
31.on('complete', function() {
32 console.log('Fastest is ' + this.filter('fastest').map('name'))
33})
34.run({ 'async': true })