Skip to content

Commit

Permalink
fix: benchmarks and run them
Browse files Browse the repository at this point in the history
Signed-off-by: Till Sanders <[email protected]>
  • Loading branch information
tillsanders committed Mar 22, 2024
1 parent 4915d42 commit d663f4d
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 108 deletions.
2 changes: 1 addition & 1 deletion benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "eventemitter3 benchmarks",
"main": "index.js",
"scripts": {
"benchmark": "find run -name '*.js' -exec ./start.sh {} \\;"
"benchmark": "find run -name '*.mjs' -exec ./start.sh {} \\;"
},
"repository": "primus/eventemitter3",
"author": "Arnout Kazemier",
Expand Down
26 changes: 12 additions & 14 deletions benchmarks/run/add-remove.js → benchmarks/run/add-remove.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict";
import Benchmark from "benchmark";

import { Suite } from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import Drip from "drip";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";

Expand All @@ -17,16 +15,16 @@ import("../../dist/index.js").then((ESMitter) => {
if (arguments.length > 100) console.log("damn");
}

var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
var ee1 = new EventEmitter1.EventEmitter(),
ee2 = new EventEmitter2.EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
drip = new Drip.EventEmitter(),
fe = new FE(),
ce = CE(),
ee = EE();

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
ee1.on("foo", handle);
ee1.removeListener("foo", handle);
Expand All @@ -35,11 +33,11 @@ import("../../dist/index.js").then((ESMitter) => {
ee2.on("foo", handle);
ee2.removeListener("foo", handle);
})
.add("EventEmitter3@5.0.1", function () {
.add("EventEmitter3", function () {
ee3.on("foo", handle);
ee3.removeListener("foo", handle);
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
master.on("foo", handle);
master.removeListener("foo", handle);
})
Expand All @@ -63,7 +61,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
24 changes: 12 additions & 12 deletions benchmarks/run/context.js → benchmarks/run/context.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

import { Suite } from "benchmark";
import Benchmark from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import Drip from "drip";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";

Expand All @@ -19,11 +19,11 @@ import("../../dist/index.js").then((ESMitter) => {
if (arguments.length > 100) console.log("damn");
}

var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
var ee1 = new EventEmitter1.EventEmitter(),
ee2 = new EventEmitter2.EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
drip = new Drip.EventEmitter(),
fe = new FE(),
ce = CE(),
ee = EE();
Expand All @@ -37,7 +37,7 @@ import("../../dist/index.js").then((ESMitter) => {
fe.on("foo", handle.bind(ctx));
ce.on("foo", handle.bind(ctx));

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
ee1.emit("foo");
ee1.emit("foo", "bar");
Expand All @@ -50,13 +50,13 @@ import("../../dist/index.js").then((ESMitter) => {
ee2.emit("foo", "bar", "baz");
ee2.emit("foo", "bar", "baz", "boom");
})
.add("EventEmitter3@5.0.1", function () {
.add("EventEmitter3", function () {
ee3.emit("foo");
ee3.emit("foo", "bar");
ee3.emit("foo", "bar", "baz");
ee3.emit("foo", "bar", "baz", "boom");
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
master.emit("foo");
master.emit("foo", "bar");
master.emit("foo", "bar", "baz");
Expand Down Expand Up @@ -90,7 +90,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"use strict";

import { Suite } from "benchmark";
import Benchmark from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import CE from "contra/emitter";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";
var Master = import("../../dist/index.js").ESMitter;

function foo() {
if (arguments.length > 100) console.log("damn");
Expand All @@ -28,8 +27,8 @@ function baz() {
return true;
}

var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
var ee1 = new EventEmitter1.EventEmitter(),
ee2 = new EventEmitter2.EventEmitter2(),
ee3 = new EventEmitter3(),
fe = new FE(),
ce = CE(),
Expand All @@ -44,14 +43,14 @@ import("../../dist/index.js").then((ESMitter) => {
ee3.on("foo", foo).on("foo", bar).on("foo", baz);
ee2.on("foo", foo).on("foo", bar).on("foo", baz);
ee1.on("foo", foo).on("foo", bar).on("foo", baz);
Master.on("foo", foo).on("foo", bar).on("foo", baz);
master.on("foo", foo).on("foo", bar).on("foo", baz);

//
// Drip is omitted as it throws an error.
// Ref: https://github.com/qualiancy/drip/pull/4
//

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
ee1.emit("foo");
ee1.emit("foo", "bar");
Expand All @@ -64,13 +63,13 @@ import("../../dist/index.js").then((ESMitter) => {
ee2.emit("foo", "bar", "baz");
ee2.emit("foo", "bar", "baz", "boom");
})
.add("EventEmitter3@5.0.1", function () {
.add("EventEmitter3", function () {
ee3.emit("foo");
ee3.emit("foo", "bar");
ee3.emit("foo", "bar", "baz");
ee3.emit("foo", "bar", "baz", "boom");
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
master.emit("foo");
master.emit("foo", "bar");
master.emit("foo", "bar", "baz");
Expand Down Expand Up @@ -98,7 +97,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
24 changes: 12 additions & 12 deletions benchmarks/run/emit.js → benchmarks/run/emit.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

import { Suite } from "benchmark";
import Benchmark from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import Drip from "drip";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";

Expand All @@ -17,11 +17,11 @@ import("../../dist/index.js").then((ESMitter) => {
if (arguments.length > 100) console.log("damn");
}

var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
var ee1 = new EventEmitter1.EventEmitter(),
ee2 = new EventEmitter2.EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
drip = new Drip.EventEmitter(),
fe = new FE(),
ce = CE(),
ee = EE();
Expand All @@ -35,7 +35,7 @@ import("../../dist/index.js").then((ESMitter) => {
master.on("foo", handle);
ce.on("foo", handle);

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
ee1.emit("foo");
ee1.emit("foo", "bar");
Expand All @@ -48,13 +48,13 @@ import("../../dist/index.js").then((ESMitter) => {
ee2.emit("foo", "bar", "baz");
ee2.emit("foo", "bar", "baz", "boom");
})
.add("EventEmitter3@5.0.1", function () {
.add("EventEmitter3", function () {
ee3.emit("foo");
ee3.emit("foo", "bar");
ee3.emit("foo", "bar", "baz");
ee3.emit("foo", "bar", "baz", "boom");
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
master.emit("foo");
master.emit("foo", "bar");
master.emit("foo", "bar", "baz");
Expand Down Expand Up @@ -88,7 +88,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
24 changes: 12 additions & 12 deletions benchmarks/run/hundreds.js → benchmarks/run/hundreds.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

import { Suite } from "benchmark";
import Benchmark from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import Drip from "drip";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";

Expand All @@ -19,11 +19,11 @@ import("../../dist/index.js").then((ESMitter) => {
return 1;
}

var ee1 = new EventEmitter1(),
ee2 = new EventEmitter2(),
var ee1 = new EventEmitter1.EventEmitter(),
ee2 = new EventEmitter2.EventEmitter2(),
ee3 = new EventEmitter3(),
master = new Master(),
drip = new Drip(),
drip = new Drip.EventEmitter(),
fe = new FE(),
ce = CE(),
ee = EE(),
Expand All @@ -43,7 +43,7 @@ import("../../dist/index.js").then((ESMitter) => {
}
}

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
for (i = 0; i < 10; i++) {
ee1.emit("event:" + i);
Expand All @@ -54,12 +54,12 @@ import("../../dist/index.js").then((ESMitter) => {
ee2.emit("event:" + i);
}
})
.add("EventEmitter3@0.1.6", function () {
.add("EventEmitter3", function () {
for (i = 0; i < 10; i++) {
ee3.emit("event:" + i);
}
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
for (i = 0; i < 10; i++) {
master.emit("event:" + i);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
24 changes: 12 additions & 12 deletions benchmarks/run/init.js → benchmarks/run/init.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

import { Suite } from "benchmark";
import Benchmark from "benchmark";

import { EventEmitter2 } from "eventemitter2";
import { EventEmitter as EventEmitter1 } from "events";
import EventEmitter2 from "eventemitter2";
import EventEmitter1 from "events";
import EventEmitter3 from "eventemitter3";
import { EventEmitter as Drip } from "drip";
import CE from "contra/emitter";
import Drip from "drip";
import CE from "contra/emitter.js";
import EE from "event-emitter";
import FE from "fastemitter";

Expand All @@ -20,21 +20,21 @@ import("../../dist/index.js").then((ESMitter) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let emitter;

new Suite()
new Benchmark.Suite()
.add("EventEmitter1", function () {
emitter = new EventEmitter1();
emitter = new EventEmitter1.EventEmitter();
})
.add("EventEmitter2", function () {
emitter = new EventEmitter2();
emitter = new EventEmitter2.EventEmitter2();
})
.add("EventEmitter3@0.1.6", function () {
.add("EventEmitter3", function () {
emitter = new EventEmitter3();
})
.add("ESMitter(main)", function () {
.add("ESMitter", function () {
emitter = new Master();
})
.add("Drip", function () {
emitter = new Drip();
emitter = new Drip.EventEmitter();
})
.add("fastemitter", function () {
emitter = new FE();
Expand All @@ -49,7 +49,7 @@ import("../../dist/index.js").then((ESMitter) => {
console.log(e.target.toString());
})
.on("complete", function completed() {
console.log("Fastest is %s", this.filter("fastest").map("name"));
console.log("Fastest is %s", this.filter("fastest").map("name").join(' & '));
})
.run({ async: true });
});
Loading

0 comments on commit d663f4d

Please sign in to comment.