kprotty / zap

An asynchronous runtime with a focus on performance and resource efficiency.
https://github.com/kprotty/zap
MIT License
447 stars 16 forks source link

Cpp benchmark - asio standalone #8

Closed kassane closed 1 year ago

kassane commented 1 year ago

No guarantee it's the best implementation or anything like that (I'm not expert in concurrent programming). However, another alternative for a library that is popular with C++ programmers is missing.

kassane commented 1 year ago

@kprotty, follow your implementation suggestion based on some examples found in the asio source.

Although it was a leap for me!

kassane commented 1 year ago

@kprotty,

I recognize that asio has more sophisticated features that perhaps lean towards your experiment as an example: asio:: awaitable<T> (C++20) std coroutines enhanced. So far I've had a lot of difficulty using it due to the need for some esoteric cxxflags from the library. (e.g.: -DASIO_HAS_CO_AWAIT).

Example: https://github.com/chriskohlhoff/asio/blob/master/asio/src/examples/cpp20/channels/throttling_proxy.cpp

kassane commented 1 year ago

@kprotty,

(std::async + std::deque) I'm looking into this solution, maybe it can help. https://github.com/akselsd/AsyncQuicksort/blob/master/quicksort.hpp#L64-L97

kassane commented 1 year ago

@kprotty , my last commit fix:

filling
shuffling
running
Values before co_await: 0 - 10000000
took 929ms

Edit

the change only uses insertSort or std::sort.

kassane commented 1 year ago

@kprotty ,

new commit - Refactored code!!!

filling
shuffling
running
took 1494ms
kassane commented 1 year ago

The new refactored version of c++20 coroutines works, slightly faster than strand.

kassane commented 1 year ago

@kprotty,

I think that the rabbit hole is currently emerging. Would it be valid to optimize further after this new refactoring? I've tried to avoid using as much of the complexity of TMP (template metaprogramming) as possible!

kassane commented 1 year ago

Hi @madmongo1,

First, I apologize for mentioning it without contacting you previously.

We are trying to get the best "possible" solution in an asynchronous qsort. I don't have much experience in using coroutines nor asio standalone coroutines.

Based on current solution which returns ±1230ms (coro-qsort).

In the last Review it is noticed that co_spawn receives an awaitable function that is immediately destroyed. That would happen on every call, right?

Note: Development environment would be equivalent to (zig c++ = clang with libc++).