[英]Is there any reason to use a synchronized HashMap rather than ConcurrentHashMap?
[英]Android Wear: Is there any reason to use a Time object rather than a Calendar object?
这就是我所知道的,如果有任何错误,请告诉我。
示例监视面(如模拟监视面 )在SDK中使用不推荐使用的Time对象来管理时间。
根据文档时间在22级(Android 5.1)中被弃用。 现在显然它仍然有很多生命,但为了未来验证代码的利益,我看着我看着切换到Calendar对象。
我相信时间和日历都是长期变量的花哨包装。 我写了这个基准来测试他们的速度。
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;
}
基准测试结果显示,在Moto 360上运行日历的速度提高了2倍。
将测试表面切换到日历表示调试器中没有泄漏内存。
所以我的问题是双重的。 我的基准测试有问题,还是确实更快? 如果是这样,Time的优点是什么,以便他们在他们的例子中使用它?
我的假设是他们只是用它来使他们的例子更容易理解。 时间是一个更直观的名称,但我想知道是否有技术原因。
编写样本时, Time
类尚未弃用。 如果我们现在写它们,我们会使用Calendar
。 使用Calendar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.