Why Const Doesn't Make C Code Faster
theartofmachinery.com
Why Const Doesn't Make C Code Faster
1–10 of 197 posts
Re: Why Const Doesn't Make C Code Faster
#2Re: Why Const Doesn't Make C Code Faster
#3overlooks the value of const qualification for the caller - if the argument is marked as const, the caller might reasonably assume the data won’t be changed.
Re: Why Const Doesn't Make C Code Faster
#4overlooks the value of const qualification for the caller - if the argument is marked as const, the caller might reasonably assume the data won’t be changed.
constFoo(x);
constBar(x);
where it couldn't make that assumption if one function wasn't const.Re: Why Const Doesn't Make C Code Faster
#5Obviously there are stupid things that can be avoided from the start but in general I prefer clean code where people write for readability and simplicity and not speed.
Re: Why Const Doesn't Make C Code Faster
#6I have done a lot of profiling work and I have observed similar things. One thing is const, another is virtual functions. A lot of people think they add overhead and avoid them for performance reasons but my profiling almost never showed them as a problem. Same for const and inline. it’s really hard to predict what the optimizer will do. Obviously there are stupid things that can be avoided from the start but in gene…
Re: Why Const Doesn't Make C Code Faster
#7Re: Why Const Doesn't Make C Code Faster
#8The compilers are smart. Let them do their thing.
Re: Why Const Doesn't Make C Code Faster
#9overlooks the value of const qualification for the caller - if the argument is marked as const, the caller might reasonably assume the data won’t be changed.
Re: Why Const Doesn't Make C Code Faster
#10I've worked with JavaScript weenies who are in love with the const declaration. They don't have an answer, though, when I ask, "Shouldn't the compiler be able to notice that a variable isn't changed in it's lifetime?" Most of the const values are just local and never leave the function but the weenies continue to stomp their feet when I use "var". The compilers are smart. Let them do their thing.