Re: Collections in .NET (C#)
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Fri, 9 Jun 2006 22:06:18 +0200
Note that you run this code as a debug build, which means with most JIT
optimizations turned off. Running the release build makes no sense either,
the JIT compiler may hoists the for loops, or completely ignore the
result(the result x is loop scoped, so not used outside the loop).
Willy.
"John J. Hughes II" <no@xxxxxxxxxxx> wrote in message
news:u8JG%23U$iGHA.3572@xxxxxxxxxxxxxxxxxxxxxxx
| Switching to 2003 you can get better performance if you stop using an
object
| and cast directly to the given value. Below is a converted sample show
the
| results which are even faster then 2005 with generics. Just sort of
depends
| on how much fexablity you have.
|
| struct tmpP
| {
| public double Getx()
| {
| return 0.00;
| }
| }
|
| private static void testRun()
| {
| tmpP[] pc = new tmpP[100000000];
|
| System.Diagnostics.Debug.WriteLine("direct");
| DateTime start = DateTime.Now;
|
| tmpP p = pc[0];
| for(int n = 0; n < 100000000; n++)
| {
| double x = p.Getx();
| }
| System.Diagnostics.Debug.WriteLine(DateTime.Now - start);
|
| System.Diagnostics.Debug.WriteLine("index");
| start = DateTime.Now;
| for(int n = 0; n < 100000000; n++)
| {
| double x = pc[0].Getx();
| }
| System.Diagnostics.Debug.WriteLine(DateTime.Now - start);
|
| System.Diagnostics.Debug.WriteLine("foreach");
| start = DateTime.Now;
| foreach(tmpP tp in pc)
| {
| double x = tp.Getx();
| }
| System.Diagnostics.Debug.WriteLine(DateTime.Now - start);
| }
|
|
| direct
| 00:00:01.1845360
| index
| 00:00:01.3559820
| foreach
| 00:00:01.6365300
|
| Regards,
| John
|
|
.
- References:
- Collections in .NET (C#)
- From: mitch
- Re: Collections in .NET (C#)
- From: Miha Markic [MVP C#]
- Re: Collections in .NET (C#)
- From: mitch
- Re: Collections in .NET (C#)
- From: John J. Hughes II
- Collections in .NET (C#)
- Prev by Date: Re: How to get the real system date
- Next by Date: General Database Question - Tables in Classes
- Previous by thread: Re: Collections in .NET (C#)
- Next by thread: Re: Collections in .NET (C#)
- Index(es):
Relevant Pages
|