Re: Collections in .NET (C#)

Tech-Archive recommends: Speed Up your PC by fixing your registry



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
|
|


.



Relevant Pages

  • Re: Bugs at my web site
    ... > an array bounds violation has occured and breaking if it has isn't ... The only question is for JIT compilers. ... Consider a constant loop, or a loop with the limit equal to the ... The JIT compiler can also test for a try/catch block and only generate ...
    (comp.lang.fortran)
  • Re: Speed wars: OCaml vs. F#
    ... That is quite common for numerical tasks because OCaml's lack of JIT ... compilation forces it to use a uniform representation of values in general. ... let rec loop zi zr i = ... probably leading OCaml to needlessly box and immediately unbox the function ...
    (comp.lang.functional)
  • Re: Managed vs Unmanaged Bare Bones Performance Test
    ... The reason for the huge difference is that the C++ compiler hoists the loop, as it sees no sensible reason to call an empty function 50000 times, the C# compiler does not do this, it simply calls the function which only contains a ret. ... True for optimized builds, the call is hoisted, but the loop is not hoisted by the JIT, the C++ compiler effectively hoists the loop. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: very slow vectorized code
    ... hence the JIT ... loop version is in favour for the JIT to accelerate. ... feature accel off ...
    (comp.soft-sys.matlab)
  • Re: Read from TCP Stream greater then buffer size
    ... If I run it with breakspoint in debug and step thru the loop iterations I ... > interact with a NNTP server to retrieve a list of news groups. ... > blocking on the stream read, the question is how to I control receiving a ...
    (microsoft.public.dotnet.languages.vb)