Skip to main content
GameDev.net gamedev.net
🔒 Locked

Timing problem

Started by taby Mar 18, 2021 at 5:32 PM 2 replies 3.8k views
Original Post
taby
taby

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​

hplus0603
hplus0603

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 };
taby
taby

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.