Hi guys
I've just made a following test:
1. VICE in C perft test depth 4: 4085603 nodes visited in 1577ms
2. VICE in JS perft test depth 4: 4085603 leaf nodes visited 2143ms
JS version is slightly slower while JS code seems to be a port of C code.
How on earth on that possible???
Just for comparison - I'm porting one of my C engines to JS and for the same position I'm getting around 1400ms in C version and 22000 in JS
Did I miss something???
Confused by perft results: VICE in C vs VICE in JS
Moderators: hgm, Rebel, chrisw
-
- Posts: 771
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Confused by perft results: VICE in C vs VICE in JS
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
- Posts: 855
- Joined: Sun May 23, 2010 1:32 pm
Re: Confused by perft results: VICE in C vs VICE in JS
C is compiled while JS is interpreted?
-
- Posts: 771
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: Confused by perft results: VICE in C vs VICE in JS
Yes! I can't believe my eyes!
JS runs in a browser (chrome) not even via nodejs
while C is compiled without optimizations
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
- Posts: 1563
- Joined: Thu Jul 16, 2009 10:47 am
- Location: Almere, The Netherlands
Re: Confused by perft results: VICE in C vs VICE in JS
There must be something wrong with your C version.maksimKorzh wrote: ↑Fri Dec 11, 2020 6:19 pm Hi guys
I've just made a following test:
1. VICE in C perft test depth 4: 4085603 nodes visited in 1577ms
2. VICE in JS perft test depth 4: 4085603 leaf nodes visited 2143ms
JS version is slightly slower while JS code seems to be a port of C code.
How on earth on that possible???
Just for comparison - I'm porting one of my C engines to JS and for the same position I'm getting around 1400ms in C version and 22000 in JS
Did I miss something???
I don't know if this is from the starting position, if it is than perft with depth 4 should take at most a few milliseconds.
Looking at the number of nodes visited it doesn't look like the starting position, still 2,5 million moves per second for perft is extremely slow.
Without bulk counting I would expect it to be at least 10 times as fast.
-
- Posts: 771
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: Confused by perft results: VICE in C vs VICE in JS
It's from this position:Joost Buijs wrote: ↑Fri Dec 11, 2020 7:56 pmThere must be something wrong with your C version.maksimKorzh wrote: ↑Fri Dec 11, 2020 6:19 pm Hi guys
I've just made a following test:
1. VICE in C perft test depth 4: 4085603 nodes visited in 1577ms
2. VICE in JS perft test depth 4: 4085603 leaf nodes visited 2143ms
JS version is slightly slower while JS code seems to be a port of C code.
How on earth on that possible???
Just for comparison - I'm porting one of my C engines to JS and for the same position I'm getting around 1400ms in C version and 22000 in JS
Did I miss something???
I don't know if this is from the starting position, if it is than perft with depth 4 should take at most a few milliseconds.
[d]r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
and I took source code from official sources mentioned in video series's links:
https://github.com/bluefeversoft/Vice_C ... Vice10.zip // C version
https://github.com/bluefeversoft/JSChes ... r/Ch63.zip // JS version
You can run perft test at depth 4 in the position above and see it on your own.
note: I've removed optimization flags from the makefile, JS version runs in chrome.
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
- Posts: 1563
- Joined: Thu Jul 16, 2009 10:47 am
- Location: Almere, The Netherlands
Re: Confused by perft results: VICE in C vs VICE in JS
Oh, I believe you, never heard of Vice, if it really runs that slow it must be doing a lot more than just perft().
For comparison using the position you show perft(4) runs in 7 milliseconds in my engine, that is 225 times faster than what Vice does.
Maybe your hardware is somewhat slower, but a 225 times slower perft() is weird.
BTW. this is with full incremental update of 3 64 bit hash-keys, the material evaluation and the game stage which is not needed for pertft() at all.
For comparison using the position you show perft(4) runs in 7 milliseconds in my engine, that is 225 times faster than what Vice does.
Maybe your hardware is somewhat slower, but a 225 times slower perft() is weird.
BTW. this is with full incremental update of 3 64 bit hash-keys, the material evaluation and the game stage which is not needed for pertft() at all.
-
- Posts: 792
- Joined: Wed Jul 19, 2006 9:58 am
Re: Confused by perft results: VICE in C vs VICE in JS
Do you have a link to your code?maksimKorzh wrote: ↑Fri Dec 11, 2020 6:19 pm Hi guys
I've just made a following test:
1. VICE in C perft test depth 4: 4085603 nodes visited in 1577ms
2. VICE in JS perft test depth 4: 4085603 leaf nodes visited 2143ms
JS version is slightly slower while JS code seems to be a port of C code.
How on earth on that possible???
Just for comparison - I'm porting one of my C engines to JS and for the same position I'm getting around 1400ms in C version and 22000 in JS
Did I miss something???
I've done a lot of JS development in recent years, and find the Vice code embarrassing - I didn't know much JS at the time, and I'd do a lot differently now, and be able to make it a lot faster.
If you're getting that kind of slowdown, there must be something amiss.
-
- Posts: 771
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: Confused by perft results: VICE in C vs VICE in JS
Oh.. how could you not hear about it?Joost Buijs wrote: ↑Fri Dec 11, 2020 8:18 pm Oh, I believe you, never heard of Vice, if it really runs that slow it must be doing a lot more than just perft().
For comparison using the position you show perft(4) runs in 7 milliseconds in my engine, that is 225 times faster than what Vice does.
Maybe your hardware is somewhat slower, but a 225 times slower perft() is weird.
BTW. this is with full incremental update of 3 64 bit hash-keys, the material evaluation and the game stage which is not needed for pertft() at all.
I was learning chess programming via following this tutorial series, without it I wouldn't ever write even a weak chess engine.
And yeah, this is full incremental update. C version uses 64bit keys, JS version 32 bit keys respectively.
It's not the problem that it's slow. The problem is that JS version runs almost as fast as C vercion while the source code is literally a port.
This is very confusing and I just can't get what did I miss.
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
- Posts: 771
- Joined: Sat Sep 08, 2018 5:37 pm
- Location: Ukraine
- Full name: Maksim Korzh
Re: Confused by perft results: VICE in C vs VICE in JS
Finally response by the author!Richard Allbert wrote: ↑Fri Dec 11, 2020 8:36 pmDo you have a link to your code?maksimKorzh wrote: ↑Fri Dec 11, 2020 6:19 pm Hi guys
I've just made a following test:
1. VICE in C perft test depth 4: 4085603 nodes visited in 1577ms
2. VICE in JS perft test depth 4: 4085603 leaf nodes visited 2143ms
JS version is slightly slower while JS code seems to be a port of C code.
How on earth on that possible???
Just for comparison - I'm porting one of my C engines to JS and for the same position I'm getting around 1400ms in C version and 22000 in JS
Did I miss something???
I've done a lot of JS development in recent years, and find the Vice code embarrassing - I didn't know much JS at the time, and I'd do a lot differently now, and be able to make it a lot faster.
If you're getting that kind of slowdown, there must be something amiss.
Richard, I didn't think I would be that lucky, you're kind of almost unreacheble via comments on youtube.
re: Do you have a link to your code?
- you mean to your VICE code or to the engine I'm porting now?
I took YOUR code from the descriptions below your series (both C and JS versions),
Link to my code is here: https://github.com/maksimKorzh/wukongJS ... /wukong.js
Run perft in browser in live mode: https://maksimkorzh.github.io/wukongJS/wukong.html (depth 3)
Richard, it's not a problem that your JS code looked like C back in those days, I like using JS that way as well, it's not a problem.
The problem is - HOW ON EARTH your JS version is only 1 second slower with "tricky position" (as you called it in your videos)
compared to the C version??? Javascript is 5 times slower than C and your JS code is almost a clone of your C code.
Could you please test it on your side? (I took code for both engines from your github)
Could you please share your JS engines? (I didn't see any at your github apart from Vice JS port)
Did you see my bitboard chess engine in C tutorial series and numerous chess programming videos inspired by your videos?
PLEASE let me know what do you think of them - your opinion is extremely important for me because you're the only man who did it in such great details. Btw, I'm referencing you and your work on Vice in many of my videos)
Didactic chess engines:
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
https://www.chessprogramming.org/Maksim_Korzh
Chess programming YouTube channel:
https://www.youtube.com/channel/UCB9-pr ... KKqDgXhsMQ
-
- Posts: 2554
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: Confused by perft results: VICE in C vs VICE in JS
modern javascript engines do JIT, of course, translating functions into optimized machine code (harder than it seems, because it's a dynamic language),
using the interpreter as a fallback in some weird cases I think (like switching at runtime based on argument type etc.)
I'd typcally expect a factor of about 4 times slowdown for JS (depends on the program, could be less or more)
an interpreter would probably run 10-100+ times slower than (optimized) C, depending on what you do
I believe JS crams everything into a double (unless bigdecimal is used, meaning very slow), so you can't really use full 64-bit integers because mantissa is 53 bits for double IIRC
knowing some of the gotchas, I think it should be possible to make your JS run faster if you're not happy with the performance - a factor of 16 seems a bit too much
Martin Sedlak