Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
dbigham
Posts: 515
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

Using clock_gettime to measure execution time is returning strange results

struct timespec start, stop;
if(clock_gettime( CLOCK_REALTIME, &start) == -1)
{
fprintf(stderr, "ERROR GETTING TIME");
}

 

... long execution ...

 

if(clock_gettime( CLOCK_REALTIME, &stop) == -1)
{
fprintf(stderr, "ERROR GETTING TIME2");
}

fprintf(stderr, "Time: %f", (double)( stop.tv_nsec - start.tv_nsec ) / (double)1000000000.0F);

 

Using this to surround something that's taking about 3 seconds to execute is resulting in output such as:

 

Time: -0.743363

 

What gives?

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using clock_gettime to measure execution time is returning strange results

Are you sure tv_sec isn't needed? I might be misinterpreting it, but it seems to have the number of seconds from Epoch, followed by the number of nanoseconds till the next second. If you are just comparing nanoseconds, you could be in a different second. Ex. 10sec 5000000nano->11sec 200000nano.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
dbigham
Posts: 515
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Using clock_gettime to measure execution time is returning strange results

Please use plain text.
Developer
BikeAtor
Posts: 62
Registered: ‎03-31-2012
My Device: Playbook
My Carrier: None

Re: Using clock_gettime to measure execution time is returning strange results

[ Edited ]

You could also give a try to Qt for Playbook :-) It's better portable (Windows/Linux/Symbian/Meego+++), easy to use, well documented etc. Qt for Playbook is alpha or beta, but most things are running fluently and Cascades will be build upon it (as I understand the things). Here is the Code for Qt:

QTimer timer;
timer.start();
... long operation
timer.elapsed();

 

Please use plain text.