DateTime optimization

  • Thread starter Thread starter ThomasR
  • Start date Start date
T

ThomasR

I've done some examination of the DateTime implementation (stepped
through Disassembly in debug mode) and find it horribly inefficient in
framework 1.0.

For example, the internal DatePart routine calculates year,month, and
day from the raw DateTime data (Ticks I assume, but not sure). To
calculate year, it goes through the first code section. To calculate
Month, it goes through the first two sections (first calculating year,
than month). Day calculation goes through all 3 sections of DatePart.

I stepped through DateTime.AddMonths and found the runtime first calls
DatePart to get Year, then calls DatePart to get Month (recalculating
year), then calls DatePart yet again to get Day (recalculating year
and month). Therefore, Year is calculated 3 times, month is
calculated 2 times, and Day calculated once.

is this really more effiencient on average than caching year and month
on the stack for the calling code of DateTime? Any word of this being
optimized in future frameworks?

For simple date manipulations where time is not required, I'm
considering writing my own DateTime structure that could be ALOT
faster!
 
Only on Framework 1.0. I'd be interested in any 1.1 data. My Visual Studio
hasn't been upgraded to 1.1 yet. I do have the 1.1 framework installed,
can't I set a 1.0 exe to run on 1.1 with the admin tools?
 
Back
Top