Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue #48

Open
kuanyui opened this issue Oct 1, 2021 · 0 comments
Open

Performance issue #48

kuanyui opened this issue Oct 1, 2021 · 0 comments

Comments

@kuanyui
Copy link

kuanyui commented Oct 1, 2021

First, thanks for your project. This library is fabulous for TypeScript as a robust strong-typed event emitter, I doesn't find any other library can do this so well.

However, I found the performance is an issue which cannot be neglected in this library. I profile some EventEmitter libraries:

const Benchmark = require('benchmark')
const EETS = require('ee-ts/lib/ee').EventEmitter
const EE3 = require('eventemitter3')
const FE = require("@foxify/events").default

let TMP = ''
function dummyFn(x) {
  TMP = x
}

class KlsOnXXX {
  run() {
    this.onHello('hello')
  }
}

class KlsEETS extends EETS {
  run() {
    this.emit('hello', 'hello')
  }
}
class KlsEE3 extends EE3 {
  run () {
    this.emit('hello', 'hello')
  }
}
class KlsFE extends FE {
  run () {
    this.emit('hello', 'hello')
  }
}

const kls_onxxx = new KlsOnXXX()
const kls_eets = new KlsEETS()
const kls_ee3 = new KlsEE3()
const kls_fe = new KlsFE()

kls_onxxx.onHello = function (ev) { dummyFn(ev) }
kls_eets.on('hello', function (ev) { dummyFn(ev) }  )
kls_ee3.on('hello', function (ev) { dummyFn(ev) }  )
kls_fe.on('hello', function (ev) { dummyFn(ev) }  )

var suite = new Benchmark.Suite
suite
.add('onXXX', function () {
  kls_onxxx.run()
})
.add('ee-ts', function () {
  kls_eets.run()
})
.add('ee3', function () {
  kls_ee3.run()
})
.add('fe', function () {
  kls_fe.run()
})
.on('cycle', function(event) {
  console.log(String(event.target));
})
.on('complete', function() {
  console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({
  'async': false, // https://benchmarkjs.com/docs#options_async
  'delay': 1
});

And the result is astonishing...

onXXX x      193,150,752 ops/sec ±4.00% (88 runs sampled)
ee-ts x        1,732,183 ops/sec ±3.64% (77 runs sampled)
ee3 x         52,713,790 ops/sec ±1.11% (89 runs sampled)
fe x         122,749,677 ops/sec ±0.55% (89 runs sampled)
Fastest is onXXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant