You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
first of all thank you for code sharing,
Can you help me please,
I tested your code in my projet, but i found the runtime is very slow, compared to the normal code (without threadpool) or compared normal thread. For exmeple my code like this:
//////////////////////////////////////////////////
void myfunction(int k){
std::vector myvetcor;
myvector.push_back (k*2.77+25/5);
}
int main()
{
{
ThreadPool pool{ 8};
for (int i = 0; i < 20000; ++i)
{
pool.enqueue([ i]() {
myfunction(i);
});
}
}
return 0;
}
////////////////////////////////////////////////////
thank you
The text was updated successfully, but these errors were encountered:
I'd say the function is too small (plus is allocating and deallocating the vector each time is called). In cases like this one, it may be counter productive to use the thread. This is because the overhead that the thread pool adds (to keep track of the queue, callbacks, etc) is too big in comparison with the time required to execute the function, which is really really small.
If you want to execute the same light function multiple times, you can probably build a less generic thread pool that is optimized for that. Nevertheless, for such simple math operations, the overhead may still be too high.
first of all thank you for code sharing,
Can you help me please,
I tested your code in my projet, but i found the runtime is very slow, compared to the normal code (without threadpool) or compared normal thread. For exmeple my code like this:
//////////////////////////////////////////////////
void myfunction(int k){
std::vector myvetcor;
myvector.push_back (k*2.77+25/5);
}
int main()
{
return 0;
}
////////////////////////////////////////////////////
thank you
The text was updated successfully, but these errors were encountered: