Re: System.Timers.Timer performance test ?
- From: "Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
- Date: Mon, 28 Nov 2005 14:05:27 -0500
Hi,
The WinXX OS is not a real time OS , therefore you cannot be 100% sure that
an event will fire at a given time.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<logdenav@xxxxxxxxxx> wrote in message
news:1133193645.397980.171630@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hello
> I'm testing the performance of the System.Timers.Timer class.
> I created a small program that create 100 User objects.
> Each USer object create a MyTimer object.
>
> The constructor of the User class contains a name and a time to wait
> for the timer.
> Calling start on the User objet initiate the MyTimer to callback in 1
> second.
>
> When the User received the callback from MyTimer, it restart a new
> timer for 1 second.
>
> It works fine with 10 users but with 100 users and more, It seems that
> few User callbacks
> do not appears.
>
> With 10 users, each second the total is : 10, 20, 30, 40, 50, ....
> With 100 users the total is : 100, 200, 270, 365, .....
> It's not regular !!!
>
> Have you an idea ?
> What will it be the best implemation to do that ?
>
> Thanks
>
> The c# program :
>
> using System;
>
> namespace TimersPerf
> {
> public delegate void MyTimerHandler (double delta);
>
>
> class MyTimer
> {
> public event MyTimerHandler CallBack;
> System.Timers.Timer t=null;
> private DateTime startTime, endTime;
> private int ms;
>
> public MyTimer(int ms)
> {
> this.ms = ms;
> }
>
> public void Set()
> {
> if (t==null)
> {
> t = new System.Timers.Timer(ms);
> t.AutoReset = false;
> t.Elapsed+=new System.Timers.ElapsedEventHandler(t_Elapsed);
> startTime = DateTime.Now;
> t.Start();
> }
> }
>
> private void t_Elapsed(object sender, System.Timers.ElapsedEventArgs
> e)
> {
> endTime = DateTime.Now;
> TimeSpan delta = endTime-startTime;
> t.Stop();
> t.Dispose();
> t = null;
> CallBack(delta.TotalMilliseconds);
> }
>
> }
>
>
>
> class User
> {
> private MyTimer t;
> private int name;
> private int ms;
> private int cpt =0;
>
> private static object obj = new object();
> private static int total = 0;
>
> public User(int name, int ms)
> {
> this.name = name;
> this.ms = ms;
> t = new MyTimer(ms);
> }
>
> public void start()
> {
> t.CallBack+=new MyTimerHandler(CallBack);
> t.Set();
> }
>
> private void CallBack(double delta)
> {
> cpt++;
> lock(obj)
> {
> total++;
> Console.WriteLine("name={0}, delta={1}, cpt={2}, total={3}", name,
> delta, cpt, total);
> }
>
> t.Set();
> }
> }
>
>
>
>
> class Class1
> {
> [STAThread]
> static void Main(string[] args)
> {
> Class1 c = new Class1();
> c.foo();
> Console.ReadLine();
> }
>
>
> public void foo()
> {
> int count = 10;
> User[] user = new User[count];
> for(int i=0; i<count; i++)
> {
> user[i] = new User(i, 1000);
> user[i].start();
> }
> }
>
> }
> }
>
.
- References:
- System.Timers.Timer performance test ?
- From: logdenav
- System.Timers.Timer performance test ?
- Prev by Date: Re: Help pls how to call .net dll from Delphi
- Next by Date: Re: Text Input Problem
- Previous by thread: System.Timers.Timer performance test ?
- Next by thread: most efficient mechanism(s) for packing/sending/unpacking data through a webservice for a smart client.
- Index(es):
Relevant Pages
|