473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help on calculate time taken to execute a function!!

1
Hi, I am currently doing a project regarding image processing. I had facing problem writing C++ code to calculate time taken to execute a function.
Can somebody help me on this. thanks.


#include "picture.h"
#include <iostream>

using namespace std;

int main()
{
int i;
int cnt = 0;

colour_picture_of_<unsigned char> in(240,320);
colour_picture_of_<unsigned char> out(240,320);

in.show("Input",0);
out.show("Output",0);

in.attach_camera();// Connect the picture to the camera
in.request_frame(); // Request frame

**************Start timer**************************
for (i = 1; i <= 10; i++ )
{
cout << "Frame " << cnt++ << endl;
}

**************End timer**************************
Jan 20 '07 #1
2 7911
willakawill
1,646 1GB
Hi, I am currently doing a project regarding image processing. I had facing problem writing C++ code to calculate time taken to execute a function.
Can somebody help me on this. thanks.


#include "picture.h"
#include <iostream>

using namespace std;

int main()
{
int i;
int cnt = 0;

colour_picture_of_<unsigned char> in(240,320);
colour_picture_of_<unsigned char> out(240,320);

in.show("Input",0);
out.show("Output",0);

in.attach_camera();// Connect the picture to the camera
in.request_frame(); // Request frame

**************Start timer**************************
for (i = 1; i <= 10; i++ )
{
cout << "Frame " << cnt++ << endl;
}

**************End timer**************************
Hi. This is one way I use to do it. You must include 'atltime.h'
Expand|Select|Wrap|Line Numbers
  1.          CFileTime cftStart;
  2.     CFileTime cftEnd;
  3.     CFileTimeSpan cftLapsed;
  4.     char message[200] = {0};
  5.  
  6.     cftStart = GetCurrentTime();
  7.  
  8. //put your code that you want to time here
  9.  
  10.     cftEnd = GetCurrentTime();
  11.     cftLapsed = cftEnd - cftStart;
  12.     sprintf_s(message, 200, "completed process in %d secs"
  13.         , cftLapsed.GetTimeSpan() / 1000);
  14.          MessageBoxA(message);
  15.  
Regarding the / 1000
this will give you the elapsed time in seconds. Change it to 60000 if you want minutes and leave it out if you want milliseconds
Good luck
Jan 20 '07 #2
macklin01
145 100+
Hi. This is one way I use to do it. You must include 'atltime.h' ...
GetCurrentTime(), CFileTime, etc. look very Microsoft-specific. A lot of image processing work/research isn't limited solely to MS platforms, and so something more cross-platform compatible may be useful. e.g.,

Expand|Select|Wrap|Line Numbers
  1. // ...
  2. #include <ctime>
  3.  
  4. time_t TicTime;
  5. time_t TocTime;
  6.  
  7. void TIC();
  8. void TOC();
  9. double StopwatchTimeInSeconds( void );
  10.  
  11. // ... 
  12.  
  13. int main( int argc, char* argv[] )
  14. {
  15.  // ...
  16.  
  17.  
  18.  // start timing here.
  19.  TIC();
  20.  
  21.  // code to time here
  22.  
  23.  // stop timing here
  24.  TOC();
  25.  
  26.  // output stopwatch value 
  27.  
  28.  cout << StopwatchValueInSeconds() << " seconds to complete" << endl;
  29.  
  30.  return 0;
  31. }
  32.  
  33. void TIC( void )
  34. { TicTime = time(NULL); }
  35.  
  36. void TOC( void )
  37. { TocTime = time(NULL); }
  38.  
  39. double StopwatchValueInSeconds( void )
  40. { return difftime(TocTime,TicTime); }
  41.  
In fact, I use that very code to time functions in my cancer simulations. e.g.,

0 seconds for angiogenesis update
49 seconds for level set and geometry maintenance

You can also use clock() functions, but I've had more trouble with those on some linux/g++ combinations, for unknown reasons. -- Paul
Jan 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Fabian | last post by:
I notice on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude100499.asp that the writer has measured the time taken to run the script down to the millisecond. ...
1
by: Simon Wadsworth | last post by:
My application uses VB6 WebClasses to handle the UI, so all requests come in via a stub ASP page. I would like to know the time taken for the request to be processed. I am trying to use the...
11
by: srkkreddy | last post by:
Hi, I have written a large program which makes multiple calls to number of functions (also written by me) of the program. Now, I want to know the collective time taken by all the calls to a...
8
by: saurabh.ss | last post by:
Hi I want to measure the time required to execute a piece of code. For example, I want to know the time required to execute a given function. How do I do it within C++? I know I got to use a...
1
by: myselfrajotia | last post by:
DEAR FRIENDS, I need a software which can calculates the time taken by a sorting program written in C language. or if there is no s/w, then is there any other alternative. plz do help me.
3
by: psbasha | last post by:
Hi, I would like to know the time taken by each function,for an application.Other than profiler ,is there any method/function available to print the duration of execution of method/function. ...
15
by: RajuRaman | last post by:
I want to know how we can calculate the time taken for the compilation of a program...pls help..
1
by: Bakarre | last post by:
To display a field from databse and calculate time different -------------------------------------------------------------------------------- Good day, i have problem to display a field from...
3
by: sivaji | last post by:
Is there any function or variable that return the time taken to execute a part or full php script .
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.