由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - stl的一个问题
相关主题
一个C++的概念问题C++11里list迭代器判空仍然知道具体的list对象吗?
C++ vector 一边遍历一边删问一个有关C++里面list的问题。
c++ template question:问一下STL里的queue, and stack 遍历的问题 (转载)
how to write a function take iterators as parameters?STL感觉实在太变态了
STL/vector引用成员变量。deque的pointer和reference是怎么回事?
怎么传container的单个地址吗?呼唤大侠们,我实在不能实现C++泛型的精神。
如何把文件内容读到2D的vector里?c++ interview: iterator 和 pointer区别?
问个土问题:Why iterator instead of array index for vector?stl container erase in a loop
相关话题的讨论汇总
话题: stl话题: vector话题: function话题: bound话题: lower
进入Programming版参与讨论
1 (共1页)
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
2
O(n^3)
O(log2(n^3))...
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

1 (共1页)
进入Programming版参与讨论
相关主题
stl container erase in a loopSTL/vector引用成员变量。
c++ pointers are iterators, why?怎么传container的单个地址吗?
about loop-invariant optimization如何把文件内容读到2D的vector里?
C++如何快速输入iterator类型名问个土问题:Why iterator instead of array index for vector?
一个C++的概念问题C++11里list迭代器判空仍然知道具体的list对象吗?
C++ vector 一边遍历一边删问一个有关C++里面list的问题。
c++ template question:问一下STL里的queue, and stack 遍历的问题 (转载)
how to write a function take iterators as parameters?STL感觉实在太变态了
相关话题的讨论汇总
话题: stl话题: vector话题: function话题: bound话题: lower