From d663f4df5995512e283aad0d54cf9e630a1bc81c Mon Sep 17 00:00:00 2001 From: Till Sanders Date: Fri, 22 Mar 2024 12:08:40 +0100 Subject: [PATCH] fix: benchmarks and run them Signed-off-by: Till Sanders --- benchmarks/package.json | 2 +- .../run/{add-remove.js => add-remove.mjs} | 26 ++++++++--------- benchmarks/run/{context.js => context.mjs} | 24 ++++++++-------- ...steners.js => emit-multiple-listeners.mjs} | 23 ++++++++------- benchmarks/run/{emit.js => emit.mjs} | 24 ++++++++-------- benchmarks/run/{hundreds.js => hundreds.mjs} | 24 ++++++++-------- benchmarks/run/{init.js => init.mjs} | 24 ++++++++-------- .../run/{listeners.js => listeners.mjs} | 14 +++++----- benchmarks/run/{once.js => once.mjs} | 24 ++++++++-------- .../run/{remove-emit.js => remove-emit.mjs} | 28 +++++++++---------- 10 files changed, 105 insertions(+), 108 deletions(-) rename benchmarks/run/{add-remove.js => add-remove.mjs} (77%) rename benchmarks/run/{context.js => context.mjs} (84%) rename benchmarks/run/{emit-multiple-listeners.js => emit-multiple-listeners.mjs} (84%) rename benchmarks/run/{emit.js => emit.mjs} (83%) rename benchmarks/run/{hundreds.js => hundreds.mjs} (81%) rename benchmarks/run/{init.js => init.mjs} (70%) rename benchmarks/run/{listeners.js => listeners.mjs} (84%) rename benchmarks/run/{once.js => once.mjs} (74%) rename benchmarks/run/{remove-emit.js => remove-emit.mjs} (81%) diff --git a/benchmarks/package.json b/benchmarks/package.json index b335a3a..39e34b9 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -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", diff --git a/benchmarks/run/add-remove.js b/benchmarks/run/add-remove.mjs similarity index 77% rename from benchmarks/run/add-remove.js rename to benchmarks/run/add-remove.mjs index d2bc080..8a03c48 100644 --- a/benchmarks/run/add-remove.js +++ b/benchmarks/run/add-remove.mjs @@ -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"; @@ -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); @@ -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); }) @@ -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 }); }); diff --git a/benchmarks/run/context.js b/benchmarks/run/context.mjs similarity index 84% rename from benchmarks/run/context.js rename to benchmarks/run/context.mjs index 30f6ce1..b7817d6 100644 --- a/benchmarks/run/context.js +++ b/benchmarks/run/context.mjs @@ -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"; @@ -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(); @@ -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"); @@ -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"); @@ -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 }); }); diff --git a/benchmarks/run/emit-multiple-listeners.js b/benchmarks/run/emit-multiple-listeners.mjs similarity index 84% rename from benchmarks/run/emit-multiple-listeners.js rename to benchmarks/run/emit-multiple-listeners.mjs index 2ad0511..ce0052d 100644 --- a/benchmarks/run/emit-multiple-listeners.js +++ b/benchmarks/run/emit-multiple-listeners.mjs @@ -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"); @@ -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(), @@ -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"); @@ -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"); @@ -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 }); }); diff --git a/benchmarks/run/emit.js b/benchmarks/run/emit.mjs similarity index 83% rename from benchmarks/run/emit.js rename to benchmarks/run/emit.mjs index ebd356e..099d548 100644 --- a/benchmarks/run/emit.js +++ b/benchmarks/run/emit.mjs @@ -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"; @@ -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(); @@ -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"); @@ -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"); @@ -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 }); }); diff --git a/benchmarks/run/hundreds.js b/benchmarks/run/hundreds.mjs similarity index 81% rename from benchmarks/run/hundreds.js rename to benchmarks/run/hundreds.mjs index 89545bd..2522cae 100644 --- a/benchmarks/run/hundreds.js +++ b/benchmarks/run/hundreds.mjs @@ -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"; @@ -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(), @@ -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); @@ -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); } @@ -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 }); }); diff --git a/benchmarks/run/init.js b/benchmarks/run/init.mjs similarity index 70% rename from benchmarks/run/init.js rename to benchmarks/run/init.mjs index c78a469..f81e345 100644 --- a/benchmarks/run/init.js +++ b/benchmarks/run/init.mjs @@ -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"; @@ -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(); @@ -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 }); }); diff --git a/benchmarks/run/listeners.js b/benchmarks/run/listeners.mjs similarity index 84% rename from benchmarks/run/listeners.js rename to benchmarks/run/listeners.mjs index 6f621fd..99542e3 100644 --- a/benchmarks/run/listeners.js +++ b/benchmarks/run/listeners.mjs @@ -1,8 +1,8 @@ "use strict"; -import { Suite } from "benchmark"; +import Benchmark from "benchmark"; -import { EventEmitter as EventEmitter1 } from "events"; +import EventEmitter1 from "events"; import EventEmitter3 from "eventemitter3"; import FE from "fastemitter"; @@ -15,7 +15,7 @@ import("../../dist/index.js").then((ESMitter) => { if (arguments.length > 100) console.log("damn"); } - var ee1 = new EventEmitter1(), + var ee1 = new EventEmitter1.EventEmitter(), ee3 = new EventEmitter3(), master = new Master(), fe = new FE(); @@ -37,14 +37,14 @@ import("../../dist/index.js").then((ESMitter) => { // event-emitter and contra/emitter do not implement `listeners`. // - new Suite() + new Benchmark.Suite() .add("EventEmitter1", function () { ee1.listeners("event"); }) - .add("EventEmitter3@0.1.6", function () { + .add("EventEmitter3", function () { ee3.listeners("event"); }) - .add("ESMitter(main)", function () { + .add("ESMitter", function () { master.listeners("event"); }) .add("fastemitter", function () { @@ -54,7 +54,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 }); }); diff --git a/benchmarks/run/once.js b/benchmarks/run/once.mjs similarity index 74% rename from benchmarks/run/once.js rename to benchmarks/run/once.mjs index be18a19..9e75caf 100644 --- a/benchmarks/run/once.js +++ b/benchmarks/run/once.mjs @@ -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"; @@ -17,26 +17,26 @@ 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.once("foo", handle).emit("foo"); }) .add("EventEmitter2", function () { ee2.once("foo", handle).emit("foo"); }) - .add("EventEmitter3@0.1.6", function () { + .add("EventEmitter3", function () { ee3.once("foo", handle).emit("foo"); }) - .add("ESMitter(main)", function () { + .add("ESMitter", function () { master.once("foo", handle).emit("foo"); }) .add("Drip", function () { @@ -55,7 +55,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 }); }); diff --git a/benchmarks/run/remove-emit.js b/benchmarks/run/remove-emit.mjs similarity index 81% rename from benchmarks/run/remove-emit.js rename to benchmarks/run/remove-emit.mjs index 755a73c..d4987fc 100644 --- a/benchmarks/run/remove-emit.js +++ b/benchmarks/run/remove-emit.mjs @@ -1,13 +1,13 @@ "use strict"; -var benchmark = require("benchmark"); +import Benchmark from "benchmark"; -var EventEmitter2 = require("eventemitter2").EventEmitter2, - EventEmitter1 = require("events").EventEmitter, - EventEmitter3 = require("eventemitter3"), - Drip = require("drip").EventEmitter, - CE = require("contra/emitter"), - EE = require("event-emitter"); +import EventEmitter2 from "eventemitter2"; +import EventEmitter1 from "events"; +import EventEmitter3 from "eventemitter3"; +import Drip from "drip"; +import CE from "contra/emitter.js"; +import EE from "event-emitter"; import("../../dist/index.js").then((ESMitter) => { const Master = ESMitter.ESMitter; @@ -16,11 +16,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(), ce = CE(), ee = EE(); @@ -41,7 +41,7 @@ import("../../dist/index.js").then((ESMitter) => { // FastEmitter is omitted as it throws an error. // - new benchmark.Suite() + new Benchmark.Suite() .add("EventEmitter1", function () { ee1.emit("foo"); ee1.emit("foo", "bar"); @@ -54,13 +54,13 @@ import("../../dist/index.js").then((ESMitter) => { ee2.emit("foo", "bar", "baz"); ee2.emit("foo", "bar", "baz", "boom"); }) - .add("EventEmitter3@0.1.6", 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"); @@ -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 }); });