473,782 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to calculate time for method execution?

how can I calculate time needed for execution of my methods in asp.net app?
Nov 18 '05 #1
2 2353
There are a number of ways...is this simply for testing purposes? You can
turn tracing on in your page directive <%@ Page Trace="True" ...%> and do
something like:

Page.Trace.Writ e("START");
CallYourFunctio nHere();
Page.Trace.Writ e("END");

and at the bottom of the page you'll see the START and END as well as how
long it took.
Alternatively, you can profile your code using a tool such as Red-Gate's
(www.red-gate.com) ANTs Profiler (full 14 day free trial)...or there are
other free ones...which should really give you deep analysis.
Finally, if you need this in more of a production scenerio, you can use
something like:

DateTime start = DateTime.Now;
CallYourFunctio nHere();
TimeSpan ts = DateTime.Now.Su btract(start);
//use ts.TotalMillise conds to get the total amount of time it took..
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"TomislaW" <to*********@ho tmail.com> wrote in message
news:em******** ******@TK2MSFTN GP14.phx.gbl...
how can I calculate time needed for execution of my methods in asp.net app?

Nov 18 '05 #2
For simple scenarios, I use:
public class CodeTimer : IDisposable
{
public CodeTimer (string msg)
{
_msg = msg;
if (_msg.Length > 0)
_msg += " ";
++_depth;
}

public CodeTimer () : this ("")
{
}

public void Dispose ()
{
Dispose(true);
// This object will be cleaned up by the Dispose method.
// Therefore, you should call GC.SupressFinal ize to
// take this object off the finalization queue
// and prevent finalization code for this object
// from executing a second time.
GC.SuppressFina lize(this);
}

public void Dispose (bool disposing)
{
if (disposing)
{
--_depth;
string indent = new String (' ' , _depth * 4);
double totalSeconds = (DateTime.Now - _start).TotalSe conds;
Debug.WriteLine If (totalSeconds > 0, indent + _msg + string.Format
("Elapsed time: {0}", totalSeconds));
}
}

~CodeTimer ()
{
this.Dispose (false);
}

DateTime _start = DateTime.Now;
string _msg;
static int _depth = 0;
}
Use it like so:

using (Com.Banshee.Ut ilities.CodeTim er c = new
Com.Banshee.Uti lities.CodeTime r ("in CreateAdapters" )) {

do stuff

}
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
5746
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is difficult to know what is going on. One of these Order Forms you can see here... http://www.cardman.co.uk/orderform.php3
77
4613
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the process starts is not especially important, but it must be complete within a small number of seconds. The operations I am performing do not take a long time (hundreds of milliseconds), but as each part of the process is complete, my worker thread...
7
16089
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
6
4152
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the end is found is less efficient than using sizeof operator , since size of the array is completely determined at compile time. i don't quite understand this. Could anyone explain to me in detail ?
1
1729
by: asad | last post by:
Hello friends, I want to show the total execution time on my site search pages as google do on its search, so pls tell me how can i do it in ASP.NET, is there any function to do it,pls tell me. Thanks.
4
6229
by: Qwert | last post by:
Hello, I do: Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString) REM Calculate a bunch of stuff. Some loops and math functions. Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString) but both A and B have the exact the same value. Is this method incorrect? When I make the function wait for 1 millisecond, A en B differ. Is there
3
2191
by: vashwath | last post by:
Hi all, I have written program for calculating the execution time of a function.Any critics (on the method of calculating execution time) are welcome. #include <stdio.h> #include <time.h> #include <limits.h> #define DENO 10
1
2661
by: Bujji | last post by:
Hi, How to calculate Heap memory used by a process in HPUX machine (Itanium) using aCC compiler at run time ( My ultimate aim is to calculate heap memory at run-time and write it into a log file)? I couldn't find any parameter in pst_status structure that defines heap memory! ANy suggestions on how to calculate it? Thanks in advance.
8
3780
by: Magesh | last post by:
Consider a block, fncall( ); /* tells me the current millisecond or something like that: time-1 */ {/* block of code for which I need to know the exec time ... ... ... } fncall( ); /* tells me the current millisecond or something like that:
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
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
8968
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...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
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
5378
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.