473,804 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on calculate time taken to execute a function!!

1 New Member
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("Outpu t",0);

in.attach_camer a();// Connect the picture to the camera
in.request_fram e(); // Request frame

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

**************E nd timer********** *************** *
Jan 20 '07 #1
2 7933
willakawill
1,646 Top Contributor
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("Outpu t",0);

in.attach_camer a();// Connect the picture to the camera
in.request_fram e(); // Request frame

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

**************E nd 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 New Member
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
2292
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. Does anyone know what tools he used to calculate these load times? -- --
1
4336
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 time-taken value in the IIS log files by I am unclear as to the precise meaning of the value recorded. Using a test WebClass on a development PC (Win2K Pro/SP4) the value recorded in the IIS log files seems to vary:
11
3261
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 specific function. Is there any way I can find this time. Thanks in advance, Raja Kiran Sandireddy.
8
46807
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 library called ctime. But I dont know what functions to use. Please tell me.
1
2365
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
4253
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. Thanks PSB
15
4349
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
1281
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 databse and calculate time different. See below my code. I hope somebody can fix the problem for me. <?php
3
8058
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
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.