-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: wineway <wangyuweihx@gmail.com>
- Loading branch information
Showing
10 changed files
with
248 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef SQK_COMMON_RING_GENERIC_ALLOCATOR_HPP_ | ||
#define SQK_COMMON_RING_GENERIC_ALLOCATOR_HPP_ | ||
|
||
#ifdef __linux__ | ||
#include <sys/mman.h> | ||
#endif | ||
|
||
#include <memory> | ||
namespace sqk::common { | ||
|
||
template <typename T> | ||
struct Allocator : std::allocator<T> { | ||
#ifdef __linux__ | ||
[[gnu::always_inline]] | ||
constexpr T* allocate(size_t n) { | ||
T* allocated = std::allocator<T>::allocate(n); | ||
madvise(allocated, sizeof(T) * n, MADV_POPULATE_WRITE); | ||
return allocated; | ||
} | ||
#endif | ||
}; | ||
} | ||
|
||
#endif // !SQK_COMMON_RING_GENERIC_ALLOCATOR_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,3 @@ target_include_directories(${PROJECT_NAME} | |
${FABRIC_INCLUDEDIR} | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include <nanobench.h> | ||
|
||
#include <deque> | ||
#include <list> | ||
|
||
#include "ring.hpp" | ||
|
||
using namespace sqk::common; | ||
|
||
int main(int argc, char* argv[]) { | ||
constexpr uint64_t iterations = 1UL * 1000 * 1000 * 10; | ||
{ | ||
RingGuard<MpscRing<int>> guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("mpsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
int i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
RingGuard<Ring< | ||
int, | ||
RingSyncType::SQK_RING_SYNC_ST, | ||
RingSyncType::SQK_RING_SYNC_ST>> | ||
guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("spsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
int i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
RingGuard<Ring< | ||
int, | ||
RingSyncType::SQK_RING_SYNC_MT_HTS, | ||
RingSyncType::SQK_RING_SYNC_ST>> | ||
guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("hts mpsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
int i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
std::deque<int> deq; | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("deque enqueue", [&] { | ||
deq.push_back(1); | ||
int i = deq.front(); | ||
deq.pop_front(); | ||
}); | ||
} | ||
{ | ||
std::list<int> deq; | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("list enqueue", [&] { | ||
deq.push_back(1); | ||
int i = deq.front(); | ||
deq.pop_front(); | ||
}); | ||
} | ||
{ | ||
RingGuard<MpscRing<uint64_t>> guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("mpsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
uint64_t i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
RingGuard<Ring< | ||
uint64_t, | ||
RingSyncType::SQK_RING_SYNC_ST, | ||
RingSyncType::SQK_RING_SYNC_ST>> | ||
guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("spsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
uint64_t i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
RingGuard<Ring< | ||
uint64_t, | ||
RingSyncType::SQK_RING_SYNC_MT_HTS, | ||
RingSyncType::SQK_RING_SYNC_ST>> | ||
guard(9216); | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("hts mpsc_ring enqueue", [&] { | ||
guard->enqueue(1); | ||
uint64_t i; | ||
guard->dequeue(i); | ||
}); | ||
} | ||
{ | ||
std::deque<uint64_t> deq; | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("deque enqueue", [&] { | ||
deq.push_back(1); | ||
uint64_t i = deq.front(); | ||
deq.pop_front(); | ||
}); | ||
} | ||
{ | ||
std::list<uint64_t> deq; | ||
ankerl::nanobench::Bench() | ||
.minEpochIterations(iterations) | ||
.run("list enqueue", [&] { | ||
deq.push_back(1); | ||
uint64_t i = deq.front(); | ||
deq.pop_front(); | ||
}); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.