0

I have made several tests for testing access times of properties and fields.

I have this method for Measuring:

  static void Measurer(Action act)
    {
        Stopwatch stop = Stopwatch.StartNew();
        for (int i = 0; i < 10000000; i++)
        {
            act.Invoke();    
        }

        stop.Stop();
        Console.WriteLine(stop.Elapsed);
    }

I have some simple class with some properties and fields, so I have two tests for this:

  Measurer(() =>
        {
            built1.LevelID = built.LevelID;
            built1.Enabled = built.Enabled;
            built1.Profile = built.Profile;
            built1.Modes = built.Modes;
        });

 Measurer(() =>
        {
            built1.levelID = built.levelID;
            built1.enabled = built.enabled;
            built1.profile = built.profile;
            built1.modes = built.modes;
        });

I am also testing different reflection methods, but here these tests are just to show the difference. Project is for 4.5 framework. So I build the project in Release x64 when I run on my laptop with i5 CPU on Windows 7 I have these results:

enter image description here

I have access to the server machine where I decided to test, it's Xeon E560 2.4 Ghz with 2 processors on Windows Server 2008 R2 and I have this result:

enter image description here

So why I have this big difference on better machine? What causes this difference? Any thoughts? I can think of different things, but this will be just suggestions, maybe somebody knows why?

Andriy Kizym
  • 1,756
  • 2
  • 14
  • 29
  • The two systems aren't exactly apples to apples. You say one is a server -- what else was it doing? Is the server 32-bit or 64? Is the laptop's CPU running faster? They're different CPUs (number of cores is likely irrelevant). – ThatBlairGuy Mar 20 '14 at 13:26
  • server is 64 bit as well as Windows 7, I compile to target only to target x64. Server is 2.4 GHz, laptop is 2.5 Ghz. I didn't expect that this can influence the access time to the properties or fields. Almost two times slower! – Andriy Kizym Mar 20 '14 at 13:32
  • Xenon is an earlier generation of CPUs than i5. That's likely to have an impact. Other potential differenes are the amount of cache memory and bus speeds. As RQDQ said, you've got a lot of variables there. – ThatBlairGuy Mar 20 '14 at 13:57
  • I understand that, but I didn't expect this to be slower almost two times, and this is server, it should be better than laptop, come on. I am not comparing with super old server. – Andriy Kizym Mar 20 '14 at 14:25
  • @anderhil - it also depends on which version of the i5 you have. The i5-4340M can go up to 3.6 Ghz (1.5 times faster than the server). – RQDQ Mar 20 '14 at 21:07

1 Answers1

1

There are a number of variables here that will make it difficult to pinpoint exactly where the difference in times is coming from. Your two environments differ greatly:

  • Different hardware (processor, ram, motherboard, etc)
  • Different versions of the operating system
  • Different software / services running

Also, if you're running the server version via remote desktop, that will affect your timing as well.

To get more useful data from this test, you would have to control more of the variables (same operating system, same software configuration, etc).

EDIT - Remote Desktop

Some thoughts on why doing this over remote desktop can affect times:

  • Console.Write operations can block. See this question. The way your test is written, it theoretically shouldn't make much of a difference but I don't know enough about the entire implementation stack to know if that difference is meaningful in your case.
  • Windows intentionally does things differently under the covers for a remote desktop session. The items that come to mind have to do with windows forms rendering, but there are likely other differences.
Community
  • 1
  • 1
RQDQ
  • 15,461
  • 2
  • 32
  • 59
  • I thought about all of this, but why it's slower, that is the question. Server is more powerful, the times are always same, there is small delta but the numbers doesn't vary a lot when run several times. can you explain more about why remote desktop influence times? – Andriy Kizym Mar 20 '14 at 13:30
  • @anderhil I added some more thoughts on remote desktop differences. Also, none of this factors in the load that your server is under at the time of the test. What else is this server doing? Is it a web server / file server / etc? – RQDQ Mar 20 '14 at 13:55
  • this server is the one we plan to move to, so it doesn't have any load now. But my Console.WriteLine is outside of measuring block, and I stop the stopwatch before writing to console. – Andriy Kizym Mar 20 '14 at 14:36
  • Do you have physical access to the server to run it there? I'm curious if you would get any significant difference running there. – RQDQ Mar 20 '14 at 18:06