Skip to content
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

Memset for distance arrays #51

Open
L1nkus opened this issue May 1, 2017 · 4 comments
Open

Memset for distance arrays #51

L1nkus opened this issue May 1, 2017 · 4 comments

Comments

@L1nkus
Copy link
Contributor

L1nkus commented May 1, 2017

Calling memset is more efficient and quicker to write, than a loop, to set all values to 0/INF.

What do you think about changing the loops in graph algorithms to memset?

@pllk
Copy link
Owner

pllk commented May 2, 2017

That's a good idea, I'll consider it. In any case, the book should mention the memset function.

@jaens
Copy link

jaens commented Sep 16, 2017

GCC will generally convert a zero-initialization loop to a memset, so there's no efficiency difference.

@L1nkus
Copy link
Contributor Author

L1nkus commented Sep 17, 2017

Only with -O3, and most judges (for instance codeforces, uva, POI) use -O2, so there's usually an efficiency difference.

@jaens
Copy link

jaens commented Sep 17, 2017

You can just put a #pragma GCC optimize ("O3") in your code instead of hand-optimizing it when you do not like the default optimization flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants