J*****n 发帖数: 4859 | 1 今天一个同事跟我说他的困惑
他有一个三维数组存成vector of vector of vector(assume i,j,k)
然后他对其中的k,进行排序,然后使用lower_bound function去查找相关的iter,重
复了2million time。
结果他发现这个的速度很慢,还不如他自己写的binary search。(慢了一倍)
我想了半天,也没想出个名堂。
照理说stl的那些基本container和function都是优化的很好的,如果要慢,也不会慢一
倍那么多。
求高手指点一二,谢谢。 |
e*****r 发帖数: 379 | |
J*****n 发帖数: 4859 | 3
No, I think what he did likes:
lower_bound(p[i][j].begin(), p[i][j].end(), some double number)
I think in this case, memory of k is contingous and search range is just
from 0 to k - 1.
【在 e*****r 的大作中提到】 : O(n^3) : O(log2(n^3))...
|
p***o 发帖数: 1252 | 4 Sounds like you are using the checked iterators.
Read your STL manual/source code to see if that could be the case.
Also you can compare asm listings to determine why.
【在 J*****n 的大作中提到】 : : No, I think what he did likes: : lower_bound(p[i][j].begin(), p[i][j].end(), some double number) : I think in this case, memory of k is contingous and search range is just : from 0 to k - 1.
|
J*****n 发帖数: 4859 | 5
We use VS 2010 here.
What's your suggestion about improvment?
【在 p***o 的大作中提到】 : Sounds like you are using the checked iterators. : Read your STL manual/source code to see if that could be the case. : Also you can compare asm listings to determine why.
|
p***o 发帖数: 1252 | 6 #define _SECURE_SCL 0
【在 J*****n 的大作中提到】 : : We use VS 2010 here. : What's your suggestion about improvment?
|
J*****n 发帖数: 4859 | 7
Thank you.
【在 p***o 的大作中提到】 : #define _SECURE_SCL 0
|
e*****r 发帖数: 379 | 8 for small scripts, it is OK to turn it off -- trouble mixing between classes
and modules for checked/unchecked
【在 p***o 的大作中提到】 : #define _SECURE_SCL 0
|
J*****n 发帖数: 4859 | 9
classes
BTW, should I put it in the main function code or the sub code where we need
it?
【在 e*****r 的大作中提到】 : for small scripts, it is OK to turn it off -- trouble mixing between classes : and modules for checked/unchecked
|