为了距离说明我们的观点,下面有一张表,包括一些基本操作所使用的大概时间。注意这些时间并不是绝对的时间,绝对时间要考虑到CPU和时钟频率。系统不同,时间的大小也会有所差别。当然,这也是一种有意义的比较方法,我们可以比叫不同操作花费的相对时间。例如,添加一个成员变量的时间是添加一个本地变量的四倍。
Action | Time |
---|---|
Add a local variable | 1 |
Add a member variable | 4 |
Call String.length() | 5 |
Call empty static native method | 5 |
Call empty static method | 12 |
Call empty virtual method | 12.5 |
Call empty interface method | 15 |
Call Iterator:next() on a HashMap | 165 |
Call put() on a HashMap | 600 |
Inflate 1 View from XML | 22,000 |
Inflate 1 LinearLayout containing 1 TextView | 25,000 |
Inflate 1 LinearLayout containing 6 View objects | 100,000 |
Inflate 1 LinearLayout containing 6 TextView objects | 135,000 |
Launch an empty activity | 3,000,000 |