Re: System.Timers.Timer performance test ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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();
> }
> }
>
> }
> }
>


.



Relevant Pages

  • About swing Timer and synchronized
    ... private Timer timer; ... public static void main{ ... MyTimer myTimer = new MyTimer; ... private void initTimer{ ...
    (comp.lang.java.programmer)
  • Re: PowerMean
    ... private int count; ... private double mean; ... private double variance; // unscaled ... void update{ ...
    (comp.lang.java.help)
  • Re: Data Object Collection Inheritance
    ... > private System.Windows.Forms.ListBox listBox1;> private System.Windows.Forms.Button cmdID;> private System.Windows.Forms.Button cmdText; ... > private void InitializeComponent() ... > // TODO: Add BaseDataCollection.IsReadOnly getter implementation> return false; ... > public sealed class SubClassCollection: ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Problem in converting to C#
    ... public delegate void delegate1 ... private void InitializeComponent() ... private void Button1_Click(object sender, System.EventArgs e) ... Private Sub Form1_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Redraw problem - please help
    ... >> public int CurrentX; ... >> public void Create ... >> private System.ComponentModel.IContainer components; ...
    (microsoft.public.dotnet.framework.drawing)