Here is what I know, if there are any errors, let me know.
Exemplary watch faces, such as the analog clock mirror , the SDK uses an outdated Time object to control time.
According to the documentation, Time is deprecated at level 22 (Android 5.1). Now, obviously, it still has a lot of life, but in the interests of the future verification code that I looked at, I looked at the transition to the Calendar object.
I believe that time and calendar are fancy wrappers for a long variable. I wrote this test to check their speed.
long timeStart = 0; long timeEndcalendarStart = 0; long timeDifference = 0; long calendarEnd = 0; long calendarDifference = 0; for (int index = 0; index < 30000; index++) { timeStart = System.currentTimeMillis(); Time testTime = new Time(); testTime.setToNow(); long mills = testTime.toMillis(false); float seconds = testTime.second; float minutes = testTime.minute; float hours = testTime.hour; timeEndcalendarStart = System.currentTimeMillis(); Calendar testCalendar = Calendar.getInstance(); long cmills = testCalendar.getTimeInMillis(); float cseconds = testCalendar.get(Calendar.SECOND); float cminutes = testCalendar.get(Calendar.MINUTE); float chours = testCalendar.get(Calendar.HOUR); calendarEnd = System.currentTimeMillis(); timeDifference += timeEndcalendarStart - timeStart; calendarDifference += calendarEnd - timeEndcalendarStart; }
Test results show that the Calendar works 2 times faster on the Moto 360.
Switching the control side of the clock to Calendar shows that there is no memory leak in the debugger.
So my question is twofold. Is there a problem with my benchmark, or is it really faster? If so, what is the advantage of time, so they used it in their examples?
My hypothesis is that they simply used it to make their examples more understandable. Time is a more intuitive name, but I would like to know if there is a technical reason.
source share