473,397 Members | 1,960 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,397 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 2130
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
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...

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.