1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-16 12:14:18 +02:00

[pzstd] Spawn less threads in tests

MinGW thread performance degrades significantly when there are
a lot of threads, so limit the number of threads spawned to ~10.
This commit is contained in:
Nick Terrell
2016-09-22 18:59:22 -07:00
parent 2b4de225e1
commit 5ca471990b
3 changed files with 20 additions and 20 deletions

View File

@ -89,14 +89,14 @@ TEST(WorkQueue, SPSC) {
TEST(WorkQueue, SPMC) {
WorkQueue<int> queue;
std::vector<int> results(10000, -1);
std::vector<int> results(50, -1);
std::mutex mutex;
std::vector<std::thread> threads;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 5; ++i) {
threads.emplace_back(Popper{&queue, results.data(), &mutex});
}
for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 50; ++i) {
queue.push(i);
}
queue.finish();
@ -105,24 +105,24 @@ TEST(WorkQueue, SPMC) {
thread.join();
}
for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 50; ++i) {
EXPECT_EQ(i, results[i]);
}
}
TEST(WorkQueue, MPMC) {
WorkQueue<int> queue;
std::vector<int> results(10000, -1);
std::vector<int> results(100, -1);
std::mutex mutex;
std::vector<std::thread> popperThreads;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 4; ++i) {
popperThreads.emplace_back(Popper{&queue, results.data(), &mutex});
}
std::vector<std::thread> pusherThreads;
for (int i = 0; i < 10; ++i) {
auto min = i * 1000;
auto max = (i + 1) * 1000;
for (int i = 0; i < 2; ++i) {
auto min = i * 50;
auto max = (i + 1) * 50;
pusherThreads.emplace_back(
[ &queue, min, max ] {
for (int i = min; i < max; ++i) {
@ -140,7 +140,7 @@ TEST(WorkQueue, MPMC) {
thread.join();
}
for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 100; ++i) {
EXPECT_EQ(i, results[i]);
}
}
@ -197,16 +197,16 @@ TEST(WorkQueue, SetMaxSize) {
}
TEST(WorkQueue, BoundedSizeMPMC) {
WorkQueue<int> queue(100);
std::vector<int> results(10000, -1);
WorkQueue<int> queue(10);
std::vector<int> results(200, -1);
std::mutex mutex;
std::vector<std::thread> popperThreads;
for (int i = 0; i < 10; ++i) {
for (int i = 0; i < 4; ++i) {
popperThreads.emplace_back(Popper{&queue, results.data(), &mutex});
}
std::vector<std::thread> pusherThreads;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 2; ++i) {
auto min = i * 100;
auto max = (i + 1) * 100;
pusherThreads.emplace_back(
@ -226,7 +226,7 @@ TEST(WorkQueue, BoundedSizeMPMC) {
thread.join();
}
for (int i = 0; i < 10000; ++i) {
for (int i = 0; i < 200; ++i) {
EXPECT_EQ(i, results[i]);
}
}