Release vs Debug

Hello everyone,
I have more general question. I am runnig my code in Debug and Release version in c++ visual studio. The code does only aritmetic tasks such as ordering the coefficinet of some variables and finding smallest one and summing them etc. When I do this for 30 numbers it runs fast (in release mode). When I increase this number to 230 it takes long time. It is still faster than the debug run but it is slower than we expect , because the code only does aritmetic jobs such as summing, substracting , ordering etc. I can not understand what is the problem. Should I change some settings in visual studio or look for the inefficiencies (if any) in my code ? Actually I do not know what can cause ineffecieny in the code..All suggestions are welcome.
Thank you so much

Hello learner999,

I would suggest posting the code. Someone may see something that is more efficient.

The biggest difference between "release" and "debug" is that "debug" adds extra code to use in debugging that "release" does not have. As I understand it.

So I can see where "release" mode would be a bit quicker.

So increasing the size of the array or having more of the array to process will slow things down. By how much I am not sure.

Andy
default 2019 release on a modern machine is very, very fast. Its your code, post it.
the biggest "strength" of "modern" c++ is its ability to HIDE loops and memory allocations, both of which can be slow, among other things. Its nice once you understand it, but the hidden stuff is brutal if you mess something up.

lots of things cause slow code. unnecessary conditions, loops, memory management mistakes, file IO mistakes, bad algorithms, hidden copying, wrong container for the job, and those are just a tiny sample...

pow() is rather slow, if you don't need it. think about just a simple sqrt .. how does the CPU DO that, what did it COST in time? (no, you can't do it better than the CPU, but can you avoid it? somtimes x*x = z*b is good enough to solve for x*x instead, eg quick distance checks just compare the squared value, not the roots, saves a step) ... rewriting even simple math can get you a lot if the wrong things are being done repeatedly.

another thing is to profile the code, to see what is taking all the time. Visual free may not have the profile tool, though, but there are free ones out there or you can roll your own with a little work.

"ordering" looks like a starting point from what you said. Sorting things takes time.
Last edited on
Topic archived. No new replies allowed.