Igo*_*gor 5 java garbage-collection
什么是更快的方法?
System.currentTimeMillis()
Run Code Online (Sandbox Code Playgroud)
要么
new Date().getTime()?
Run Code Online (Sandbox Code Playgroud)
知道经过的时间有更快的解决方案吗?
Pet*_*rey 10
如果你这样做
new Date()
Run Code Online (Sandbox Code Playgroud)
它叫
/**
* Allocates a <code>Date</code> object and initializes it so that
* it represents the time at which it was allocated, measured to the
* nearest millisecond.
*
* @see java.lang.System#currentTimeMillis()
*/
public Date() {
this(System.currentTimeMillis());
}
Run Code Online (Sandbox Code Playgroud)
所以它调用System.currentTimeMillis()并创建一个立即丢弃的对象.
如果你很幸运,逃逸分析将删除冗余对象,性能将大致相同.
但是,我不认为Escape Analysis会启动并且只是打电话
long start = System.currentTimeMillis();
// do something
long time = System.currentTimeMillis() - start;
Run Code Online (Sandbox Code Playgroud)
笔记:
| 归档时间: |
|
| 查看次数: |
1044 次 |
| 最近记录: |