System time

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

Kovan,

You can always call the GetSystemTime API function through the P/Invoke
layer.

You will have to convert from a SYSTEMTIME structure to a DateTime
though.

Hope this helps.
 
Hi,
I wonder if there are any others ways (mehtods, properties) to get the
system time than DateTime.Now.Ticks

Regards from Kovan
__________________________________________________________________ R u
kidding me Ya right ICQ#: 149146797 Current ICQ status: + More ways to
contact me
__________________________________________________________________
 
Kovan Akrei said:
I wonder if there are any others ways (mehtods, properties) to get the
system time than DateTime.Now.Ticks

Well, there may be - but what do you want them to do differently to
just using DateTime.Now?
 
Well, I'm programming threads and I would like to test different versjons of
my program package using different synkronisation methods. I would like to
chech how long it takes to execute the program.
Second thing is that I would like to see how many threads C# kan generate in
for example 10 seconds.

Kovan
 
Kovan,

How many threads that can be generated is not going to be completely a
function of the language that you use, but rather, the machine it is
performed on. Machines with more processors, for example, will be able to
create new threads quicker.

However, comparing the way that .NET creates threads vs the Win32 API on
the same machine is a different story, as there is more overhead when .NET
creates them as opposed to say Win32.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kovan Akrei said:
Well, I'm programming threads and I would like to test different versjons of
my program package using different synkronisation methods. I would like to
chech how long it takes to execute the program.
Second thing is that I would like to see how many threads C# kan generate in
for example 10 seconds.

Kovan
 
Kovan Akrei said:
Well, I'm programming threads and I would like to test different versjons of
my program package using different synkronisation methods. I would like to
chech how long it takes to execute the program.
Second thing is that I would like to see how many threads C# kan generate in
for example 10 seconds.

And what's wrong with using DateTime.Now for that purpose? It'll be
less accurate than a high-performance counter, but if you run your
benchmark for a sufficiently long time, it shouldn't be a problem.
 
Hi,
Thanks for replying. I'm totaly aware of the difference between thread
making in .Net and windows. I have created a simulation package for dicrete
event simulation based on simula.I want to perform different tests on the
same maschine with the same configuration. I have to know how long each test
takes in seconds. How many threads are made and so on. AT the same time I
would like to compare the performance of my package programmed by C# vs
asimiliar package in Java. That is why I need get the system time at the
begining and end of each test.

Kovan

Nicholas Paldino said:
Kovan,

How many threads that can be generated is not going to be completely a
function of the language that you use, but rather, the machine it is
performed on. Machines with more processors, for example, will be able to
create new threads quicker.

However, comparing the way that .NET creates threads vs the Win32 API on
the same machine is a different story, as there is more overhead when .NET
creates them as opposed to say Win32.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Kovan Akrei said:
Well, I'm programming threads and I would like to test different
versjons
of
my program package using different synkronisation methods. I would like to
chech how long it takes to execute the program.
Second thing is that I would like to see how many threads C# kan
generate
 
I was just wondering if there were any other more accurate mehtods that
returns the time in seconds very accurate.

Kovan
 
Kovan Akrei said:
I was just wondering if there were any other more accurate mehtods that
returns the time in seconds very accurate.

DateTime.Now will return the time accurate to between 10 and 55ms,
depending on your OS. If you're benchmarking for reasonable periods of
time (preferrably minutes rather than seconds) that should easily be
accurate enough.
 
How about if I want to run a test let say for 50 seconds. Do I still use
DateTime?
What I do now is using DateTime.Now.Ticks and multiply it with 10 million
for each second. But is there a better way doing the same in .Net? I do not
want to use any win32 API.

Kovan
 
Kovan Akrei said:
How about if I want to run a test let say for 50 seconds. Do I still use
DateTime?

Yes, that would be fine.
What I do now is using DateTime.Now.Ticks and multiply it with 10 million
for each second. But is there a better way doing the same in .Net? I do not
want to use any win32 API.

Don't bother with Ticks. Just use:

DateTime start = DateTime.Now;

// Do stuff

DateTime end = DateTime.Now;

TimeSpan timeTaken = end-start;
 
Back
Top