Why C++ instead of C#?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Mergi
Posts: 127
Joined: Sat Aug 21, 2021 9:55 pm
Full name: Jen

Re: Why C++ instead of C#?

Post by Mergi »

R. Tomasi wrote: Sun Sep 19, 2021 11:17 pm
Even if I'm on team C# on this one, I will change the reference C version to get the same changes. This redundant LSB thingy is still buggin me - I suspect it's an optimization that only shows a strong effect on some CPUs, so I'd like to have it. To make the comparision fair, it should also be done in the C version. So when I'm onto that, I'll implement the algorithmic changes into the C version while I'm at it.

Thing is, I'm on vacation and my gf won't be too happy if I spend the whole day coding, so bear with me if it might take me a day or two.
Yep, even if we might be inclined to believe that these things get optimized in the C version (most likely they do), we shouldn't just rely on the compiler. Same with the IsKingSafe function that i saw got changed in the last update.
Enjoy your vacation! ;)
User avatar
lithander
Posts: 881
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Why C++ instead of C#?

Post by lithander »

klx wrote: Sun Sep 19, 2021 11:05 pm
lithander wrote: Sun Sep 19, 2021 9:11 pm Version 1.4: 28132ms to complete, about 48M NPS.

The C reference takes 16837ms to complete at about 70M NPS. So the C# code as of version 1.4 is only 30% slower.
Hm, how do you calculate this? I'd say this makes the C version 1.67x faster than C#.
30% slower = 70M NPS - 30% (of 70M NPS) = 70M NPS - 21M NPS = 49M NPS which is more or less what I have measured for the C# version.

1.67x faster seems wrong to me. Because 1.67 x 48M NPS = 80 NPS but I measured only 70M NPS. More correct would be 1.5x faster than C#.

I think we can say the C version is 1.5x faster or 50% faster or the C# version is 30% slower. It's all saying the same thing.
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

lithander wrote: Sun Sep 19, 2021 11:58 pm 30% slower = 70M NPS - 30% (of 70M NPS) = 70M NPS - 21M NPS = 49M NPS which is more or less what I have measured for the C# version.

1.67x faster seems wrong to me. Because 1.67 x 48M NPS = 80 NPS but I measured only 70M NPS. More correct would be 1.5x faster than C#.

I think we can say the C version is 1.5x faster or 50% faster or the C# version is 30% slower. It's all saying the same thing.
I understand that, but the times don't match the NPS numbers. Did you not run the same tests for them?
[Moderation warning] This signature violated the rule against commercial exhortations.
User avatar
lithander
Posts: 881
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Why C++ instead of C#?

Post by lithander »

On the github page I have included the log for each version. I took that data as basis for the summary in the forum post.

The NPS are a little different for each test position and not automatically accumulated and so I guesstimated the average for the summary. But I can't see where you think it does contradict he performance logs?
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

lithander wrote: Mon Sep 20, 2021 8:45 am But I can't see where you think it does contradict he performance logs?
Because you wrote:

C# 28132ms, 48M NPS
C 16837ms, 70M NPS

This doesn't add up since 48M * 28.132 = 1350M nodes and 70M * 16.837 = 1179M nodes. So I'm assuming there's a typo or mis-estimate somewhere.
[Moderation warning] This signature violated the rule against commercial exhortations.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

klx wrote: Mon Sep 20, 2021 3:37 pm
lithander wrote: Mon Sep 20, 2021 8:45 am But I can't see where you think it does contradict he performance logs?
Because you wrote:

C# 28132ms, 48M NPS
C 16837ms, 70M NPS

This doesn't add up since 48M * 28.132 = 1350M nodes and 70M * 16.837 = 1179M nodes. So I'm assuming there's a typo or mis-estimate somewhere.
Accumulated there are 1 361 558 651 nodes total (assuming I did not misstype on my calculator). Divided by 28.132s that yields 48.398 NPS and dividing by 16.837s yields 80.867 NPS. That means the C code is 1.671 times faster than the C# code, or - alternatively formulated - the C# code is 40.1% slower.
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

klx wrote: Sun Sep 19, 2021 11:05 pm Hm, how do you calculate this? I'd say this makes the C version 1.67x faster than C#.
R. Tomasi wrote: Mon Sep 20, 2021 3:57 pm Accumulated there are 1 361 558 651 nodes total (assuming I did not misstype on my calculator). Divided by 28.132s that yields 48.398 NPS and dividing by 16.837s yields 80.867 NPS. That means the C code is 1.671 times faster than the C# code, or - alternatively formulated - the C# code is 40.1% slower.
Right, this is what I wrote originally, but Thomas keeps arguing it's wrong:
lithander wrote: Sun Sep 19, 2021 11:58 pm 1.67x faster seems wrong to me. Because 1.67 x 48M NPS = 80 NPS but I measured only 70M NPS.
[Moderation warning] This signature violated the rule against commercial exhortations.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

klx wrote: Mon Sep 20, 2021 4:02 pm
klx wrote: Sun Sep 19, 2021 11:05 pm Hm, how do you calculate this? I'd say this makes the C version 1.67x faster than C#.
R. Tomasi wrote: Mon Sep 20, 2021 3:57 pm Accumulated there are 1 361 558 651 nodes total (assuming I did not misstype on my calculator). Divided by 28.132s that yields 48.398 NPS and dividing by 16.837s yields 80.867 NPS. That means the C code is 1.671 times faster than the C# code, or - alternatively formulated - the C# code is 40.1% slower.
Right, this is what I wrote originally, but Thomas keeps arguing it's wrong:
lithander wrote: Sun Sep 19, 2021 11:58 pm 1.67x faster seems wrong to me. Because 1.67 x 48M NPS = 80 NPS but I measured only 70M NPS.
I see no point arguing in either direction, since the facts are there for everyone to see. I don't think Thomas intentionally gave wrong figures, since he clearly stated that it's a guesstimate. To put it in the words a wise man once said to me "Use the source, Luke!"
klx
Posts: 179
Joined: Tue Jun 15, 2021 8:11 pm
Full name: Emanuel Torres

Re: Why C++ instead of C#?

Post by klx »

R. Tomasi wrote: Mon Sep 20, 2021 4:12 pm I see no point arguing in either direction, since the facts are there for everyone to see. I don't think Thomas intentionally gave wrong figures, since he clearly stated that it's a guesstimate. To put it in the words a wise man once said to me "Use the source, Luke!"
Where's the source though? The only C timing I see is earlier in the thread when it run at closer to 20 sec. So the other obvious explanation is that 16.837s was a typo. Or how did it end up that fast? That's all I'm trying to establish, it's not about arguing.
[Moderation warning] This signature violated the rule against commercial exhortations.
R. Tomasi
Posts: 307
Joined: Wed Sep 01, 2021 4:08 pm
Location: Germany
Full name: Roland Tomasi

Re: Why C++ instead of C#?

Post by R. Tomasi »

klx wrote: Mon Sep 20, 2021 4:34 pm
R. Tomasi wrote: Mon Sep 20, 2021 4:12 pm I see no point arguing in either direction, since the facts are there for everyone to see. I don't think Thomas intentionally gave wrong figures, since he clearly stated that it's a guesstimate. To put it in the words a wise man once said to me "Use the source, Luke!"
Where's the source though? The only C timing I see is earlier in the thread when it run at closer to 20 sec. So the other obvious explanation is that 16.837s was a typo. Or how did it end up that fast? That's all I'm trying to establish, it's not about arguing.
Using the source would, in this case, mean that you use the source, compile it, run it on your machine, and post your findings here ;)

I actually would love to see runs on different machines. I really suspect that the performance difference might not be the same across all CPUs.