🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Timing problem

Started by
2 comments, last by taby 3 years, 3 months ago

In my code, in thread_func I attempt to print out a value every second (every 1000000000 nanoseconds). It prints out all of the time though. Surely I'm missing something simple? If you find a solution, look me up on codementor.io – i'm Shawn Halayka (not sure if I'm allowed to say that?)

Edit: See https://github.com/sjhalayka/udpspeed_5_load_balancing/blob/main/main.cpp

Advertisement

You're posting way too much code, making it very hard to see the part that really matters.

You also don't say what part of the code you're talking about – just “trying to print on an interval.”

I'm assuming the call to elapsed.count() is the timer you're interested in? At that point, notice that you don't reset it, and you test against 0. You might want to compare with something like last_reported_at_ticks instead, if that's the area of the code you're worried about?

enum Bool { True, False, FileNotFound };

Thanks for your analysis. I am starting two DOS boxes: one running “udpspeed localhost 1920” (the sender), and the other running “udpspeed 1920” (the receiver).

Sorry for the code overload. Instead, I put the whole code up at https://github.com/sjhalayka/udpspeed_5_load_balancing/blob/main/main.cpp

I'm not sure* why the value of elapsed.count() was increasing like such, so I ended up rewriting the entire timing code in thread_func(). It works good now…. except that it's an order-of-magnitude slower than the older version of the code. I'm assuming that it's because of all the mutex locking and unlocking? I tried increasing the packet size, and that increases the speed, but it's still roughly an order-of-magnitude too slow.

* Well, it seems that mixing high-precision time stamps from different threads gives “wonky” behaviour.

This topic is closed to new replies.

Advertisement