PC硬件环境,i7 3.4GHz 16G,用 Android Studio 的 Android 模拟器分别模拟了 64 位和 32 位的 Android (ver 7.1.1) 模拟环境,以及一台旧手机作为真机环境,做20亿次的加法运算,记录了开始和完成的时间,作为简单的性能基准测试,在以上三个环境中,分别做了 9 次测试,采集测试结果如下:
单位:毫秒 | |||
64位模拟器 | 32位模拟器 | 小米4C | |
1 | 2267 | 4199 | 3393 |
2 | 2236 | 4118 | 3351 |
3 | 1952 | 4333 | 3407 |
4 | 1846 | 3695 | 3404 |
5 | 1611 | 4403 | 3416 |
6 | 1759 | 3753 | 3404 |
7 | 2309 | 4251 | 3406 |
8 | 1954 | 4486 | 3410 |
9 | 2333 | 3997 | 3389 |
平均耗时 | 2030 | 4137 | 3398 |
测试结果仅供参考,测试代码十分简单:
public void OnCLickCalc(View view)
{
TextView textView1 = findViewById(R.id.textView2);
TextView textView2 = findViewById(R.id.textView4);
TextView textView3 = findViewById(R.id.textView5);
// 在开始和结束分别取时间
Calendar calendar1 = Calendar.getInstance();
long value = 0;
for (long i = 0; i < 2000000000; i++)
{
value = value + 1;
}
// 记录结束时间
Calendar calendar2 = Calendar.getInstance();
// 输出开始时间和结束时间
String str = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS")).format(calendar1.getTime());
textView1.setText(str);
str = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS")).format(calendar2.getTime());
textView2.setText(str);
// 计算毫秒时间差
long x = calendar2.getTimeInMillis() - calendar1.getTimeInMillis();
textView3.setText(Long.toString(x));
}
Q群讨论: 236201801