Sign in to follow this  

vector operation and loop, which is quicker?

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all: Say in C++, I have a vector of data say: vector<int> array(10000); If I do some calculation on the array, is for loop quicker or some vector/matrix routine defined in libraries like numerical recipes quicker? Thanks

Share this post


Link to post
Share on other sites
it really depends on your implementation and theirs. Using theirs is most likely the fastest way to get working code unless you have to do a lot of hacking and chopping to get your data in the right format for theirs.

as an example, say you are writing a function to find which of a few objects is closer. If you used a library function to calculate the distance it computes the whole distance. Since you only need the relative order of the objects you could write it yourself and use distance squared and save yourself the calculation of multiple square roots. The library writer can't do this since he has promised you distance.

Share this post


Link to post
Share on other sites

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this