Hey Jow Forums, I'm currently learning c++ and I was trying to redo some of this year's AoC to get some practice...

Hey Jow Forums, I'm currently learning c++ and I was trying to redo some of this year's AoC to get some practice. As babby's first program I redid day 1, originally done in MATLAB, and this is where the mindfuck begin. I know my MATLAB solution was retarded and there are much better and faster ways to find duplicate numbers (pls no bully). However, I wanted to first use a direct translation to compare c++ and MATLAB speeds. To my surprise, the ultra fast c++ was 10x-20x slower than Matlab.
Here is the code (pls no bully):
MATLAB:
jprev=length(sum);
iprev=length(sum);
for i=1:length(sum)
for j=1:length(sum)
if sum(i) == sum(j) && i~=j
if max(i,j) < max(iprev,jprev)
result=sum(i);
jprev=j;
iprev=i;
end
end
end
end

C++:
int imin = len * 150;
int jmin = len * 150;
int value;
for (i = 0; i < len * 150/2; i++)
{
//find(freqact.begin(), freqact.end(), freqact[i]);
for (j = 0; j < len * 150; j++)
{
if (freqact[i]==freqact[j] && max(i, j) < max (imin, jmin) && i != j)
{
value=freqact[i];
jmin = j;
imin = i;
}

}
}

C++ was run through Visual Studio.
What the fuck? I thought C++ was supposed to be the fastest

Attached: Cattura.png (306x140, 4K)

Other urls found in this thread:

rust-lang.org/production
firecracker-microvm.github.io/
twitter.com/SFWRedditGifs

try with -Ofast

>I'm currently learning c++
Found your first problem. Learn anything besides that.

C# ?

You're probably running c++ in debug mode, try in release

Well microsoft Java is not a good choice either. Learn anything besides C++,C# or java.

why not C++?

You know, I'm having my doubts about this as the learning curve is pretty steep and the documentation sucks, however I already know Matlab and Python, and i'd say they cover my scripting needs pretty well (MATLAB for academia, control systems and proprietary libraries, Python for its ease of use, syntax machine learning and open community). C++ covers my need for a lower level language and basically these three languages are used for 99% of the stuff in my field (automotive C/C++ is widely used in empbedded, ECUs, etc and i already know some C). However i'm not sure if a slight boost in my curriculum is worth the hassle of learning C++, as this is something i'm doing in my spare time while i study more strictly automotive related subjects

Oh forgot to mention that i also like programming to some degree, I know that anything besides MATLAB won't relly boost my curriculum that much to be worth putting up with unless you actually like doing that

And we have a winner.
It is now 100x faster than MATLAB.
Please excuse me for my retardation