lawrence-laz / generic-pipeline

A simple, fast and generic implementation of the pipeline design pattern.
MIT License
6 stars 0 forks source link

Benchmarks vs Mediator #14

Open Naxaliav opened 1 year ago

Naxaliav commented 1 year ago

Hi 👋, have you looked into this library? https://github.com/martinothamar/Mediator (it uses source generators underneath). Just wondering what would be the benchmarks vs this implementation :)

lawrence-laz commented 1 year ago

Hi, I have looked into it a bit, you can check out the feature parity table in the main readme.md.

I don't have a benchmark to compare it to this library though, but I'd expect Mediator to be faster. I might try it out a bit later.

Generally thinking about GenericPipeline though, if a design calls for a standard mediator pattern implementation to handle application requests, I'd always go with either MediatR or this Mediator. GenericPipeline is a better fit only where you need more control, either your handlers/behaviors are dynamically changing or the pipeline is being build at runtime based on user configuration (and handlers are not part of dependency injection container). At least it was specifically built with such scenario in mind. 🙂

lawrence-laz commented 1 year ago

So I did an initial benchmark and surprisingly Mediator is 40 ns slower than GenericPipeline:

Method Mean Allocated
MethodCall 7.513 ns -
GenericPipeline 38.024 ns -
Mediator 79.192 ns -

I'll have to play with this a bit more, might be missing something. Work in progress benchmark is currently on test/mediator-benchmarks branch.