2

I have the following function:

public static int getDiffHour(Date first) {
        int hoursBetween = Hours.hoursBetween(new LocalDate(first), new LocalDate()).getHours();
        return hoursBetween;
    }

I am trying to get difference in hours between two dates.

Here is my Traceview:

enter image description here

The function is taking crazy amounts of time and resource to execute - what do I miss here. My service is getting killed on 5.0.1 due to this enormous CPU time taken by this function.

Edit:

Digging down deeper, I find that 99% of the CPU time is taken by LocalDate init. Is there a way I can avoid that and supply a date precalculated?

Edit 2: After implementing Joda 2.6:

enter image description here

Community
  • 1
  • 1
Skynet
  • 7,820
  • 5
  • 44
  • 80

1 Answers1

2

This issue might have been solved with the newest Joda-Time-release v2.6 because the class initialization of class DateTimeZone (where you observe huge amounts of time spent) no longer calls the method setProvider0(), see also this commit.

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126
  • I will just download the latest jar and update here - actually my bug seems to be double edged. Its a mix of memory consumption and [this](https://code.google.com/p/android/issues/detail?id=63793) – Skynet Jan 05 '15 at 11:11
  • It has dropped from 90.7% to 89.9 percent with the new jar. Consuming a lot of resources to init the LocalDate. – Skynet Jan 05 '15 at 12:15
  • @Skynet Can you please show your new trace (with Joda-Time v2.6)? – Meno Hochschild Jan 05 '15 at 12:45
  • Bro, I think I had misinterpreted / used a wrong trace file. The performance has increased tremendously, I am posting the new traceview image in my original question. – Skynet Jan 05 '15 at 13:36