iOS Question Timers and How Long does a loop take

SFE

Member
Licensed User
I am reading some serial data across a BLE stream. If I send bytes every 500msec the display updates with the new values. As I drop down to 400msec the display "freezes". If I enter a breakpoint the display updates.

So, here are my questions.
1) It appears that my code must be taking to long to process the data so I was going to measure the amount of time each loop took. Since I am new to B4X I have wasted time trying to figure out how to do this. I thought I would set a timer for 50msec and add 1 to a variable and read the difference. I constantly get 1 for my variable value. Meaning it made it to the timer sub but never returns. So I thought well maybe once it goes tot the timer sub it disables the timer so I re-enable the timer but it still does not return to the sub. So, obviously I don't enter understand the timer method.
2) What is the most efficient way to measure how long a loop takes, in milliseconds (or ticks). DateTimeUtils?
3) Also If I am incorrect on why my display is not updating then feel free to clarify


Thanks for helping a newbie
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
B4X:
Dim t1 as Long = DateTime.Now
'execute what you want to measure
Dim t2 as Long = DateTime.Now
Dim elapsedTicks as Long = t2 - t1
 
Upvote 0

SFE

Member
Licensed User
Thanks for the quick reply. It worked exactly as you showed. I have learned that between Erel and the community help is easily available,
Thanks again
 
Upvote 0
Top