Re: Timing of functions in C#

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



The first time a method is called it is JIT'd. The Just In Time compiler
will compile the IDL, then will use the compiled version for subsequent
calls.

--
Floyd


"DrOrbit" <nlsa@xxxxxxxx> wrote in message
news:1112456865.214794.71490@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I am working on a rather large program that hits several methods
> multiple times. In looking for ways to speed it up, I have discovered
> something odd. The first time I call a method, it's about 30 times
> slower than any subsequent call. This is true for all the methods that
> I have tested. For example, the first call might take 30 milliseconds
> whereas all subsequent calls take less than 1 ms. I would like to
> understand why this is happening.
>
> An example method looks like this:
>
> public void computeVecP () // Escobal 5.3
> {
> VecP.X = (SatObs.Sat.KepElements.CosArgPerigee *
> SatObs.Sat.KepElements.CosLongAsc) -
> (SatObs.Sat.KepElements.SinArgPerigee *
> SatObs.Sat.KepElements.SinLongAsc * SatObs.Sat.KepElements.CosInc);
>
> VecP.Y = (SatObs.Sat.KepElements.CosArgPerigee *
> SatObs.Sat.KepElements.SinLongAsc) +
> (SatObs.Sat.KepElements.SinArgPerigee *
> SatObs.Sat.KepElements.CosLongAsc * SatObs.Sat.KepElements.CosInc);
>
> VecP.Z = SatObs.Sat.KepElements.SinArgPerigee *
> SatObs.Sat.KepElements.SinInc;
> }
>
> Each term is "a property of a property of a property" and all values
> have been pre-computed. In other words,
> "SatObs.Sat.KepElements.CosArgPerigee" is declared as
> public double CosArgPerigee{get{return cosArgPerigee;}
> set{cosArgPerigee=value;}}
>
> If I substitute simple variables (i.e. "X" for
> "SatObs.Sat.KepElements.CosArgPerigee") then the time difference
> disappears. Therefore I conclude that C# is spending a long time
> locating the first property look-up but somehow doesn't need to do it
> again for subsequent calls. I hope that I'm making sense here. Is
> there a better or more complete explanation?
>


.



Relevant Pages

  • Re: Branch prediction
    ... > the first time the branch was encountered. ... Are CPUs able ... trying to hand-assemble some code to run faster than the compiler. ... very effective for tight inner loops.) ...
    (freebsd-hackers)
  • Re: Delphi seems to have gone nuts...
    ... one I'm editing and one which is being compiled. ... and ALL of my working source code is in that folder. ... > compiler is always just using the existing DCU file, ... Not the first time. ...
    (alt.comp.lang.borland-delphi)
  • Re: Redundant IL generated by the compiler
    ... The compiler is doing what you told it to do. ... So if you are that concerned with doing it right first time and not wasting ... to optimization; however, I'm a firm believer of doing things right the ... unrolling) because the JIT would do a better job of it seeing that it's ...
    (microsoft.public.dotnet.framework.clr)
  • Re: In the Matter of Herb Schildt: a Detailed Analysis of "C: The Complete Nonsense"
    ... It is not the sole source of subsequent claims that Schildt ... “Functions are not of type void; functions are of various ... using a standard compiler, and nobody was by definition before 1989. ... By the time the 3rd edition was published, however, practically everybody was using a standard-conforming compiler, because all the compiler writers were working hard on conformance whilst the Standard was still in development. ...
    (comp.lang.c)
  • Re: Delays opening documents "http://host/document.doc"
    ... but I'd assume that the first time it's having to ... On a rebooted system try opening a different document, ... > order of magnitude longer to open the document than all subsequent runs. ... > Dim w ...
    (microsoft.public.scripting.vbscript)