Created
February 2, 2018 09:47
-
-
Save gxcsoccer/ee2c4efef328095a8e320984d2d8558b to your computer and use it in GitHub Desktop.
一层继承
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Benchmark = require('benchmark'); | |
const benchmarks = require('beautify-benchmark'); | |
const suite = new Benchmark.Suite(); | |
const util = require('util'); | |
const assert = require('assert'); | |
class A { | |
calculate() { | |
return 1000000 * 1000000; | |
} | |
} | |
class B extends A {} | |
// add tests | |
suite | |
.add('class A', function() { | |
const a = new A(); | |
a.calculate(); | |
}) | |
.add('class B', function() { | |
const b = new B(); | |
b.calculate(); | |
}) | |
.on('cycle', function(event) { | |
benchmarks.add(event.target); | |
}) | |
.on('start', function() { | |
console.log('\n node version: %s, date: %s\n Starting...', process.version, Date()); | |
}) | |
.on('complete', function done() { | |
benchmarks.log(); | |
}) | |
.run({ async: false }); | |
// node version: v8.9.4, date: Thu Jan 25 2018 19:42:13 GMT+0800 (CST) | |
// Starting... | |
// 2 tests completed. | |
// class A x 152,448,289 ops/sec ±1.41% (78 runs sampled) | |
// class B x 71,289,074 ops/sec ±1.73% (82 runs sampled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment