Why is list.size()>0 slower than list.isEmpty() in Java?

后端 未结 9 1922
误落风尘
误落风尘 2020-12-13 03:58

Why is list.size()>0 slower than list.isEmpty() in Java? On other words why isEmpty() is preferable over size()>0?<

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 04:20

    I'm sorry, but your benchmark is flawed. Take a look at Java theory and practice: Anatomy of a flawed microbenchmark for a general description on how to approach benchmarks.


    Update: for a proper benchmark you should look into Japex.

提交回复
热议问题