Skip to content

Instantly share code, notes, and snippets.

@gxcsoccer
Created February 2, 2018 09:50
Show Gist options
  • Save gxcsoccer/bf4eba514d7553b1a0ee8b7bbf391139 to your computer and use it in GitHub Desktop.
Save gxcsoccer/bf4eba514d7553b1a0ee8b7bbf391139 to your computer and use it in GitHub Desktop.
两层继承
'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 {}
class C extends B {}
// add tests
suite
.add('class A', function() {
const a = new A();
a.calculate();
})
.add('class B', function() {
const b = new B();
b.calculate();
})
.add('class C', function() {
const c = new C();
c.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:41:40 GMT+0800 (CST)
// Starting...
// 3 tests completed.
// class A x 151,005,771 ops/sec ±1.33% (82 runs sampled)
// class B x 31,828,118 ops/sec ±1.31% (82 runs sampled)
// class C x 29,303,519 ops/sec ±2.23% (79 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment