49 minutes ago, BitFlipper wrote
Which audio related APIs require passing along more than a few parameters like length, IntPtr etc? The whole point of the benchmark is to show the overhead of a P/Invoke call. The audio APIs are pretty simple so I don't understand your point.
Correct, the intention was to make it sync, hence the lack of "...Async" at the end.
DoSomething and DoSomethingAsync is purely used to show the overhead of making a non-async vs async/await call. We need to compare an async op to something. If you don't have a non-async baseline, how will you know what async adds to the picture?
Also I have shown how the async/event pattern is an order of magnitude faster than async/await pattern. You can have IO with much lower overhead than what you can possibly get with await/async.
I'm not sure how your conclusion is that my tests don't show anything useful.
1) When using the audio APIs, your entire audio data has to be marshalled. PInvoke can be very efficient in some circumstances, but its not free. Trying to benchmark the impact of marshalling with different data structures will give you a false impression of the impact.
2) Your missing the point, the inner workings of DoSomething are an inherently synchronous operation. The inner workings of audio IO are not synchronous. The compiler can do different things with your example than it can real APIs. To make your benchmark even vaguely comparable, you'd need to do something asynchronous inside DoSomething and then make DoSomething a synchronous wrapper around that.
3) Your Async/Await example isn't calling a real Projected asynchronous API, so it's adding all the overhead of the Task class, whereas real Projected APIs use the IAsyncOperation COM interface and the Projection takes care of making it look the same to the language. Again, it's an Apples/Oranges comparison.
You need to actually measure what you are really doing, instead of creating examples that are only superficially similar.