Skip to content

Instantly share code, notes, and snippets.

@gxcsoccer
Created February 2, 2018 09:51
Show Gist options
  • Save gxcsoccer/63329b98be0eda7ae48d8ad41d8ebfd2 to your computer and use it in GitHub Desktop.
Save gxcsoccer/63329b98be0eda7ae48d8ad41d8ebfd2 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 {}
class D extends C {}
// 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();
})
.add('class D', function() {
const d = new D();
d.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:44:14 GMT+0800 (CST)
// Starting...
// 4 tests completed.
// class A x 145,754,540 ops/sec ±1.31% (83 runs sampled)
// class B x 32,004,297 ops/sec ±1.97% (83 runs sampled)
// class C x 17,180,225 ops/sec ±3.51% (83 runs sampled)
// class D x 14,760,139 ops/sec ±5.36% (81 runs sampled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment