mirror of
https://github.com/facebook/zstd.git
synced 2025-07-28 00:01:53 +03: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:
@ -89,7 +89,7 @@ TEST(Pzstd, LargeSizes) {
|
||||
Options options;
|
||||
options.overwrite = true;
|
||||
options.inputFiles = {inputFile};
|
||||
options.numThreads = numThreads;
|
||||
options.numThreads = std::min(numThreads, options.numThreads);
|
||||
options.compressionLevel = level;
|
||||
ASSERT_TRUE(roundTrip(options));
|
||||
errorGuard.dismiss();
|
||||
|
@ -20,12 +20,12 @@ TEST(ThreadPool, Ordering) {
|
||||
|
||||
{
|
||||
ThreadPool executor(1);
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
executor.add([ &results, i ] { results.push_back(i); });
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
EXPECT_EQ(i, results[i]);
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,7 @@ TEST(ThreadPool, AllJobsFinished) {
|
||||
std::atomic<bool> start{false};
|
||||
{
|
||||
ThreadPool executor(5);
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
executor.add([ &numFinished, &start ] {
|
||||
while (!start.load()) {
|
||||
// spin
|
||||
@ -45,7 +45,7 @@ TEST(ThreadPool, AllJobsFinished) {
|
||||
}
|
||||
start.store(true);
|
||||
}
|
||||
EXPECT_EQ(1000, numFinished.load());
|
||||
EXPECT_EQ(10, numFinished.load());
|
||||
}
|
||||
|
||||
TEST(ThreadPool, AddJobWhileJoining) {
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user