473,241 Members | 1,967 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,241 software developers and data experts.

C# code benchmark performance

Hi,

I have various chunks of code i want to benchmark to see how long they take
to do.

What i'd like to do is check the time at start of code then check time at
end of time to see how long it took. I need better accuracy than just
milliseconds

I'm looking for the time to be very accurate and to give similar results to
the
QueryPerformanceFrequency();
QueryPerformanceCounter();

that i have used in a previous C++ program.

This can give values accurate to microseconds.

Thanks In Advance
Macca
Dec 6 '05 #1
6 2125
System.TimeSpan TS;

DateTime nw = DateTime.Now;

................ your code ...........

TS = new TimeSpan(DateTime.Now.Ticks - nw.Ticks);

System.Diagnostics.Debug.WriteLine("This took " +
Convert.ToString(TS.TotalMilliseconds) + " ms");

Hope this helps :)

Enjoy,

Nick.

Software News Blog: http://www.mysoftwareblog.com/
Personal Blog: http://viri.demon.nl/blog/

Dec 6 '05 #2
You called also do PInvoke and use
QueryPerformanceFrequency();
QueryPerformanceCounter();

Dec 6 '05 #3
Or if you're using 2.0 the System.Diagnostics.Stopwatch class is
provided.

BravesCharm wrote:
You called also do PInvoke and use
QueryPerformanceFrequency();
QueryPerformanceCounter();


Dec 6 '05 #4
Hmm, seems i didn't read your question properly, you can replace
TotalMilliSeconds with Ticks to get the result in ticks (computer
cannot be more specific then ticks when time in concerned if i can
remember correctly).

Dec 6 '05 #5
ViRi wrote:
Hmm, seems i didn't read your question properly, you can replace
TotalMilliSeconds with Ticks to get the result in ticks (computer
cannot be more specific then ticks when time in concerned if i can
remember correctly).


Use QueryPerformanceCounter(), I think that's the best you can get
(resolution is microseconds or even less, depending on the
QueryPerformanceFrequency()). You'll have to [DllImport] it though.

hth,
Max

Dec 6 '05 #6

Markus Stoeger wrote:
Use QueryPerformanceCounter(), I think that's the best you can get
(resolution is microseconds or even less, depending on the
QueryPerformanceFrequency()). You'll have to [DllImport] it though.


It's the best you can get unless you happen to have some special
hardware device installed. Again, if you're using 2.0 the Stopwatch
class basically wraps this API so you only need to [DllImport] if
you're using 1.1 or lower.

Brian

Dec 6 '05 #7

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

Similar topics

16
by: Duncan Lissett | last post by:
Is there a Python implementation of Martin Richards benchmark Bench? Be interesting to add it to these www.lissett.com/ben/exp/bench1.htm
15
by: Duncan Lissett | last post by:
I'd appreciate any suggestions on how to make faster Python implementations of Richards benchmark. Perhaps there are obvious problems that can be corrected? http://www.lissett.com/ben/bench1.htm
0
by: julio | last post by:
Hello Guys, AlphaServer EV6 processor 500mhz/1Gm memory with Linux mysql> SELECT BENCHMARK(1000000,ENCODE("hello","goodbye")); +----------------------------------------------+ |...
3
by: Steve | last post by:
Hi, I'm currently looking a porting our Windows Codewarrior based C++ projects to MinGW and/or Visual Studio and I'm just wondering if there is a 'standard' suite of benchmark programs I can...
2
by: Matthijs van Waveren | last post by:
"Your opportunity to be a RECOGNIZED EXPERT in the HPC Community" The SPEC High Performance Group is seeking candidates for a benchmark suite based on Message Passing Interface (MPI)...
2
by: ke zhang | last post by:
Hi, We are building a portal web site using ASP.NET, the peak number of users is expected to be around 1 million. Is there good information about ASP.NET performance benchmark? Is there any...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
16
by: Jorge | last post by:
Webkit r34469 vs. Opera 9.50 : 3.00x as fast 6339.6ms(Opera) 2109.8ms (Webkit) ----- FF3.0 (final) vs. Opera 9.50 : 1.94x as fast 6339.6ms (Opera) 3269.6ms (FF3)
37
by: Jack | last post by:
I know one benchmark doesn't mean much but it's still disappointing to see Python as one of the slowest languages in the test: ...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.