-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinkedTreeMap效率怎么样,和HashMap相比呢? #1596
Comments
刚刚测了一遍,效率还是有差距的。如下: 插入十万条数据测试(单位微秒): LinkedTreeMap花费时间为:40945 LinkedTreeMap花费时间为:35710 LinkedTreeMap花费时间为:37687 获取十万条数据测试(单位微秒): LinkedTreeMap花费时间为:31972 LinkedTreeMap花费时间为:32927 LinkedTreeMap花费时间为:33777 |
I think the major difference is: The member elements of this object are maintained in order they were added by |
@lihy70
|
The reason why |
JsonObject的底层用的是LinkedTreeMap,Google自己写了一套。应该是有序的红黑树Map。 插入时间复杂度为O(lgn) + 左旋/右旋等等。查找时间复杂度为O(lgn) + 左旋/右旋等等。
而自带的HashMap,插入基本为O1, 查找基本为O1。就算有冲突,大于8,也会默认转为红黑树,优化的非常好。
那为什么Google要专门写一套呢?有人对比过效率么?
The text was updated successfully, but these errors were encountered: