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