josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.06k stars 147 forks source link

[benchmark] benchmark for various thread pools, but I am not sure if it is rigorous enough #406

Closed KonghaYao closed 5 months ago

KonghaYao commented 10 months ago

The result is below

Running "Worker Pool in Nodejs" suite...
Progress: 100%

  WorkerPool:
    31 ops/s, ±0.52%   | 3.13% slower

  TinyPool:
    32 ops/s, ±0.75%   | fastest

  Piscina:
    17 ops/s, ±5.95%   | 46.88% slower

  Threads:
    14 ops/s, ±1.17%   | slowest, 56.25% slower

Finished 4 cases!
  Fastest: TinyPool
  Slowest: Threads

My source code is here. https://github.com/KonghaYao/workerpool/tree/benchmark/benchmark Every library need to run 40 tasks. The task is to have a function in the worker that takes a string as input and returns it reversed to main thread.

But I am not sure if it is rigorous enough, can anyone help me? 😊

josdejong commented 10 months ago

I think in a good benchmark, you can distinguish:

In your current benchmark, you have a negligible task, and you mix starting up new threads with actually executing the task. Since reversing a short string takes 0ms and starting a worker takes something like 50ms, I expect you're mostly measuring starting up 4 or 8 workers right now (depending on how many CPU's you have). I don't think that is your intention?