阵VS性能的ArrayList [英] Array vs ArrayList in performance

查看:119
本文介绍了阵VS性能的ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个类型的对象和Object类型的ArrayList中的阵列之间的性能比较好?

Which one is better in performance between Array of type Object and ArrayList of type Object?

假设我们有动物对象的数组:兽兽[] 和ArrayList的: ArrayList的名单<动物>

Assume we have a Array of Animal objects : Animal animal[] and a arraylist : ArrayList list<Animal>

现在我做的动物[10] list.get(10)
哪一个应该会更快,为什么?

Now I am doing animal[10] and list.get(10) which one should be faster and why?

推荐答案

有pretty明显,数组[10]比array.get(10)速度更快,因为后来在内部做了同样的电话,但增加了开销的函数调用加上额外的检查。

It is pretty obvious that array[10] is faster than array.get(10), as the later internally does the same call, but adds the overhead for the function call plus additional checks.

现代JIT们却会优化这在一定程度上,你很少担心这个,除非你有一个非常关键的性能应用,这已测得为你的瓶颈。

Modern JITs however will optimize this to a degree, that you rarely have to worry about this, unless you have a very performance critical application and this has been measured to be your bottleneck.

这篇关于阵VS性能的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆