« first day (2280 days earlier)      last day (569 days later) » 

6:00 AM
Consider the following function:

f(vector<Obj> vec) {
...
std::sort(vec);
...
}


vec can be a huge vector (even millions of objects), but the objects have a fairly simple comparison operator.
The sorting operation takes the most time in f, lets say around 70%.
This function is called hundreds of times (sequentialy), with different vec each time.
Each function call is independent of another.
What do you think of the following approaches -
1. Using std::sort(std::execution_policiy::par...) but only one thread running f
 
 
3 hours later…
9:11 AM
Since std::cout << std::string("this is a test") << std::endl; works, then why std::cout << "thread hash:" << std::hash<std::thread::id>(std::this_thread::get_id()) does not work, whereas std::cout << "thread hash:" << std::hash<std::thread::id>{}(std::this_thread::get_id()) works?
 
9:22 AM
@John std::hash is a type, it doesn't have a constructor that takes an argument, it has an operator() overload to calculate the hash
I guess it should've been named std::hash_generator instead
 
9:47 AM
I see. Thank you so much.
A question about gtest:
Is it possible to run each test case in a different\sepreate process?
 
Pretty sure it is, I don't know if there's a gtest-native way to do it. But if you have a gtest executable it can spit out an xml and some test driver can use that to execute every one in a seperate process
We do that with our gtest exectuables with ctest (from cmake), they do that automatically
works with every xUnit compatible unit testing lib/framework
 
Thank you for the tips. I will try to achieve this goal with ctest.
 
 
4 hours later…
1:48 PM
I can't figure out what's the Big-Oh notation for this one:
s = 0;
for (i = 0; i < m; i++)
for (j = 0; j < i*i; j++)
for (k = 0; k < j; k++)
s++;

I tested it out in C++ and it seems to me like it is exponential but I am not sure. I can't put it in a code snippet but they are nested for loops, so three levels of nest
and s++ inside the last nested for loop
 
 
1 hour later…
nwp
3:13 PM
I think you're going about this wrong. Trying it out doesn't help you past trivial examples.
The first loop runs m times, so we know the complexity is O(m*something). The next loop runs i*i times. i is on average m/2, so we get m²/4, but the constant doesn't matter, so we get O(m*m²*lastloop).
And the last loop runs j times which is on average i*i/2 times which is m*m/8 times giving you a total of O(m^5) if I didn't make a mistake.
 

« first day (2280 days earlier)      last day (569 days later) »