Benchmarks are incorrect
See original GitHub issueYou’re using GlobalSetup/Cleanup instead of IterationSetup/Cleanup to create the Publisher, so after the first few runs TryEnqueue just starts returning false without doing any work.
Once you fix that, you’ll start getting warnings that the op count is too low to get legitimately valid results.
Once everything is fixed, you’ll probably get something like this, if you use a message size of 128, queue capacity of 33554432 bytes, and 246723 operations per iteration. (e.g. [Benchmark(Description = "Enqueue messages", OperationsPerInvoke = 246723)]
and for (var i = 0; i < 246723; ++i)
)
Of course, per machine, YMMV…
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|---------------------------------------------------------- |---------:|---------:|---------:|-------:|----------:|
| 'Enqueue messages' | 543.8 ns | 4.19 ns | 3.50 ns | - | - |
| 'Enqueue messages (zero-copy)' | 547.2 ns | 2.78 ns | 2.32 ns | - | - |
| 'Enqueue messages (zero-copy, func pointers)' | 557.0 ns | 3.71 ns | 3.29 ns | - | - |
| 'Enqueue and dequeue messages (buffered allocating)' | 724.7 ns | 5.08 ns | 4.50 ns | 0.0284 | 152 B |
| 'Enqueue and dequeue messages (buffer reuse)' | 712.3 ns | 6.32 ns | 5.27 ns | - | - |
| 'Enqueue and dequeue messages (zero-copy)' | 709.4 ns | 13.67 ns | 15.20 ns | - | - |
| 'Enqueue and dequeue messages (zero-copy, func pointers)' | 718.9 ns | 7.67 ns | 6.80 ns | - | - |
You don’t have the zero-copy ops yet, but you can review a future PR at https://github.com/StirlingLabs/interprocess
It’s still quite fast, but 7ns/op is 28 CPU cycles/op at 4ghz (between 7 and 36 GP instructions), which is a dead giveaway that no work was being done; it’s literally impossibly fast, it has to just be checking a value and returning false. Putting the benchmark into debug mode (BenchmarkRunner.Run(typeof(Program).Assembly, new DebugInProcessConfig());
) and stepping into it confirmed it.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
I updated the enqueue message benchmark test code. I will update the README with the latest numbers soon. Thanks for reporting it @TYoungSL.
Hey, happy to take ideas/PRs in small chunks. Can you do a short design write-up/proposal on each change first? We can review and get them in. I need to be careful here because this is heavily used at Microsoft for many of our services.