Replying quickly...

A LocalDate and a DateMidnight in UTC ought to be effectively identical, 
as they are internally. Hence, converting between them is perfactly 
safe, if inconvenient.

However, in fact they use different calculation styles in the Period 
constructor. DateMidnight works from milliseconds, LocalDate has to 
extract the field values.

Whether any tuning can be done is another matter.

Stephen


Paul Field wrote:
> Hi,
> 
> My application has to work out the difference, in days, between two dates a 
> lot. So, I've been investigating the performance of different approaches. 
> Currently, we're using YearMonthDays and I was thinking of moving us to 
> LocalDate but I've noticed that the performance is not as good.
> 
> There are two approaches:
>     Approach 1 : the 'obvious' - create a period of type 'days' from the two 
> dates
>     Approach 2 : convert to DateMidnight in UTC, then create a period of type 
> 'days' from the two DateMidnights
> 
> Here are the results (times in milliseconds are in brackets) together with 
> the key piece of code:
> 
> YearMonthDay - approach 1 (735ms)
>             new Period(ymd1, ymd2, PeriodType.days()).getDays();
> 
> YearMonthDay - approach 2  (234ms)
>             DateMidnight date1 = ymd1.toDateMidnight(DateTimeZone.UTC);
>             DateMidnight date2 = ymd2.toDateMidnight(DateTimeZone.UTC);
>             new Period(date1,date2,PeriodType.days()).getDays();
> 
> LocalDate - approach 1 (1328ms)
>             new Period(ldate1,ldate2, PeriodType.days()).getDays();
> 
> LocalDate - approach 2 (531ms)
>             DateMidnight date1 = ldate1.toDateMidnight(DateTimeZone.UTC);
>             DateMidnight date2 = ldate2.toDateMidnight(DateTimeZone.UTC);
>             new Interval(date1, date2).toPeriod(PeriodType.days()).getDays();
> 
> 
> FYI: I'm running a simple timing loop that iterates through the calculation 
> 200,000 times (and I do this a few times before the final timing, to 
> instantiate cached objects, load classes etc). We're running on the Java 5 
> VM. The YearMonthDays and LocalDates are just created using the default 
> constructors.
> 
> So, firstly is there any particular reason why converting to DateMidnight is 
> a bad idea for this algorithm? Next, is there any way to get the performance 
> of YearMonthDay from LocalDate for this algorithm?
> 
> Thanks,
> 
> ------------------
> Paul Field
> Global Markets Research IT
> Deutsche Bank
> ---
> 
> This e-mail may contain confidential and/or privileged information. If you
> are not the intended recipient (or have received this e-mail in error)
> please notify the sender immediately and destroy this e-mail. Any
> unauthorized copying, disclosure or distribution of the material in this
> e-mail is strictly forbidden.
> 
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to