I need to test a performance of some code of mine.
I tried using the Environment.Tic kCount but its resolution is too low (from
the MSDN remarks: The resolution of the TickCount property cannot be less
than 500 milliseconds.), I also tried the DateTime and it also gives me
minimum resolution of 500 milliseconds.
But I need to measure much less the 500 milliseconds, I need it to be
several milliseconds.
How can I do that?
--------
Thanks
Sharon 13 10578
Hi,
QueryPerformanc eFrequency and QueryPerformanc eCounter are the methods
you are looking for. Note that both are Win32 method and you will need
to pinvoke them. you will find the signatures on www.pinvoke.net. http://www.pinvoke.net/default.aspx/...ceCounter.html
=?Utf-8?B?U2hhcm9u?= <Sh*****@newsgr oups.nospam> wrote in
news:B9******** *************** ***********@mic rosoft.com: I need to test a performance of some code of mine. I tried using the Environment.Tic kCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be less than 500 milliseconds.), I also tried the DateTime and it also gives me minimum resolution of 500 milliseconds. But I need to measure much less the 500 milliseconds, I need it to be several milliseconds. How can I do that?
-------- Thanks Sharon
Here is some code I use that wraps the QueryPerformanc eCounter API:
using System;
using System.Runtime. InteropServices ;
using System.Componen tModel;
using System.Threadin g;
namespace PAB
{
public class HiPerfTimer
{
[DllImport("Kern el32.dll")]
private static extern bool QueryPerformanc eCounter(out long
lpPerformanceCo unt);
[DllImport("Kern el32.dll")]
private static extern bool QueryPerformanc eFrequency(out long lpFrequency);
private long startTime ;
private long stopTime;
private long freq;
/// <summary>
/// ctor
/// </summary>
public HiPerfTimer()
{
startTime = 0;
stopTime = 0;
freq =0;
if (QueryPerforman ceFrequency(out freq) == false)
{
throw new Win32Exception( ); // timer not supported
}
}
/// <summary>
/// Start the timer
/// </summary>
/// <returns>long - tick count</returns>
public long Start()
{
QueryPerformanc eCounter(out startTime);
return startTime;
}
/// <summary>
/// Stop timer
/// </summary>
/// <returns>long - tick count</returns>
public long Stop()
{
QueryPerformanc eCounter(out stopTime);
return stopTime;
}
/// <summary>
/// Return the duration of the timer (in seconds)
/// </summary>
/// <returns>doub le - duration</returns>
public double Duration
{
get
{
return (double)(stopTi me - startTime) / (double) freq;
}
}
/// <summary>
/// Frequency of timer (no counts in one second on this machine)
/// </summary>
///<returns>long - Frequency</returns>
public long Frequency
{
get
{
QueryPerformanc eFrequency(out freq);
return freq;
}
}
}
}
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Sharon" wrote: I need to test a performance of some code of mine. I tried using the Environment.Tic kCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be less than 500 milliseconds.), I also tried the DateTime and it also gives me minimum resolution of 500 milliseconds. But I need to measure much less the 500 milliseconds, I need it to be several milliseconds. How can I do that?
-------- Thanks Sharon
Think DateTime.Now is 10ms accurate. Not sure if that is too much for your
app. Also, this link seems to suggest Environment.Tic kCount is 1ms accurate
based on interpretation of the article and empirical evidence. Not sure. http://www.informit.com/guides/print...eqNum=241&rl=1
--
William Stacey [MVP]
"Sharon" <Sh*****@newsgr oups.nospam> wrote in message
news:B9******** *************** ***********@mic rosoft.com...
|I need to test a performance of some code of mine.
| I tried using the Environment.Tic kCount but its resolution is too low
(from
| the MSDN remarks: The resolution of the TickCount property cannot be less
| than 500 milliseconds.), I also tried the DateTime and it also gives me
| minimum resolution of 500 milliseconds.
| But I need to measure much less the 500 milliseconds, I need it to be
| several milliseconds.
| How can I do that?
|
| --------
| Thanks
| Sharon
If you are using .Net 2.0, check out the Stopwatch class. You call
it's Start method, then call it's Stop method and check the Elapsed
property to get the elapsed time. I believe it will use a high
resolution timer if the hardware supports it. Check the
IsHighResolutio n field to find out.
Sharon <Sh*****@newsgr oups.nospam> wrote: I need to test a performance of some code of mine. I tried using the Environment.Tic kCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be less than 500 milliseconds.), I also tried the DateTime and it also gives me minimum resolution of 500 milliseconds. But I need to measure much less the 500 milliseconds, I need it to be several milliseconds.
I use System.Diagnost ics.Stopwatch
But in any case, I think it's a bad idea to measure such a small
period. You should repeat your operation a thousand times and get the
overall time, then divide by a thousand. This will avoid edge-effects
&c.
--
Lucian
Hi
Doing so you also time background tasks with higher priority, which is not
necessary under your control. If you run 1000 times code1 at noon and
compare it with 1000 runs of code2 you started at 9:00 AM, you may have a
huge difference in background tasks, sustained, over the duration of one of
your 1000 times of execution, but not on the other. Maybe irrelevant, in
general, but has to be aware of the possibility.
Vanderghast, Access MVP
"Lucian Wischik" <lu***@wischik. com> wrote in message
news:5j******** *************** *********@4ax.c om... Sharon <Sh*****@newsgr oups.nospam> wrote:I need to test a performance of some code of mine. I tried using the Environment.Tic kCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be less than 500 milliseconds.), I also tried the DateTime and it also gives me minimum resolution of 500 milliseconds. But I need to measure much less the 500 milliseconds, I need it to be several milliseconds.
I use System.Diagnost ics.Stopwatch
But in any case, I think it's a bad idea to measure such a small period. You should repeat your operation a thousand times and get the overall time, then divide by a thousand. This will avoid edge-effects &c.
-- Lucian
Yet another suggestion, this one involves using the TimeSpan:
DateTime start = DateTime.Now;
....
TimeSpan end = DateTime.Now.Su btract(start); // you could just do DateTime.Now -
// start also
Console.WriteLi ne(end.TotalMil liSeconds);
The DateTime.Now and Environment.Tic kCount minimum resolution is 500
milliseconds. Only above this time you can get the 10ms accuracy.
-------
Thanks
Sharon
I'm using the .NET 1.1 and not 2.0 so I can't use the Stopwatch class.
-------
Thanks
Sharon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark A. Washburn |
last post by:
/*
SIEVE OF ERATOSTHENES from BYTE magazine --------------------
-- compiled with jdk 1.1.7b with optimize on ( -O)
-- Run times on 300 MHz Pentium 2 Windows 95
-- in order of output, from fresh boot
-------------------------------------------------------------
|
by: Bond |
last post by:
Hi! I'd like to measure the performance of my web page. I'd like to
set a timer on the page to start when a user clicks on a link, or
submit... anything where the browser requests a page from the server.
The idea would be to set a hidden form variable to the current time
when an action occurs, then when the page from the server is returned,
I can match the new time to the old time and get the difference in
order to measure the...
|
by: Sebastian Werner |
last post by:
Howdy,
I currently develop the javascript toolkit qooxdoo
(http://qooxdoo.sourceforge.net), some of you heard it already.
We have discovered a slowdown on Internet Explorers performance when
creating objects with some data and store them in a global object
registry. It take some time to get this example extracted from our
codebase. The attached file (take a look at it please) shows the exact
problem. The time for each object increases...
|
by: Andrew Jacobs |
last post by:
I am using C# to write an application that migrates documents from one
version of an XML schema/DTD to later one. Much of the document has the same
structure in the two versions and I use XMLDocument.ImportNode to copy
unchanged sub-trees between the old and new document but this takes much
longer than it should.
I profiled the code and found that when ImportNode copies an element it
initialises any default attributes defined for the...
|
by: cranium.2003 |
last post by:
hello,
If i wrote a C function then how to know that its costlier
in terms of processing time,execution,compilation.
I have written 2 functions for one problem but dont understand which
one is best from Opereating System's overhead point of view. so i want
tool that measure it.
If this is not right place to ask then tell me where to ask in any
other forum.
| |
by: Mario Soto |
last post by:
Hi. i hava a postresql 7.4.2 in a production server.
tha machine is a Pentium IV 2,6 GHZ AND 1 GB IN RAM with lINUX RH 9.0.
The postresql.conf say:
#---------------------------------------------------------------------------
# RESOURCE USAGE (except WAL)
#---------------------------------------------------------------------------
|
by: dunleav1 |
last post by:
I have a process that does inserts that runs 50% slower that Oracle and
Mssql.
Queries normally take 50% slower than normal.
DB2, Oracle, Mssql all are configured on same os, same disk array (raid
1/0 - 15k disks) but DB2 I/O seems to be significantly slower.
Tablespaces are SMS with automatic prefetch set.
My thought was to create the log buffer array as large as possible so I
don't have to switch to disk much. I'm running circular...
|
by: mjan |
last post by:
Hello,
could you please advice on how to measure replication performance
in Oracle, DB2 & MS SQL Server RDBMS installed in Windows servers ?
I've got two servers with databases installed and configured,
I prepared set of data using DBGEN from TPC and I already imported them
into databases.Also, I configured the replication.
Now I have to do a test with a few kind of replications method
implemented in these RDMBS, but I don't know which...
|
by: kostas |
last post by:
Hi,
Trying to dump a set<int(s) in a vector (v) my guess was that
v.insert(v.end(),s.begin(),s.end())
would be at least as efficient as
copy(s.begin(), s.end(), back_inserter(v))
It turn out that it is almost two times slower (even without using
reserve() before copy) and that's because it traverses the set twice.
I'm posting it as an exception to the usual (and usually correct)
advise
"Prefer member functions to algorithms".
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |