ChessUSA.com TalkChess.com
Hosted by Your Move Chess & Games
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C# Performance
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions Flat
View previous topic :: View next topic  
Author Message
Lucas Braesch



Joined: 31 May 2010
Posts: 1756

PostPost subject: Re: C# Performance    Posted: Sat Feb 04, 2012 8:31 pm Reply to topic Reply with quote

Richard Allbert wrote:
Quote:

But I think Richard might be in a somewhat different performance place, where he does need to analyse the performance of his C# code now.


certainly am! I'm hoping to get some time on this tomorrow, I'll post the speed to d5 from the start position, and some more detail of the structure.
[/quote]
I think your problem is not how to optimize the SquareIsAttacked function, but why do you need it in the first place ?

Here's what I do in my program DoubleCheck (written in C). It should give you some ideas:
* calculate a bitboard dcheckers, representing the potential discovery checkers (pieces that can give discovered check if they move out of the "ray")
* calculate a bitboard pinned, representing the pinned pieces (pieces that can give self check if they move out of the "ray")
rays are of course bitboards calculated once at initialization, so testing for self check or discovered check is very fast.

Whenever I calculate something like this, I only do it after I play a move, and store the result in a board stack. When I undo a move, I just read the value from the stack. This divides by 2 the time spent on these calculations, of course.

I also do the following things in my code, that are useful for the search but not for perft
* dynamically calculate piece on square tables
* discovery checker bitboard
* a check flag which is a property of my move object (rather struct). I have the following: check=0 (no check) check=1 (direct check) check=2 (discovered check). This is very useful in the search: checks are typically extended, and when a check is a discovered check, I never trust the SEE which has some implications in the search and especially the qsearch.

But even with those things (useless for pure perft), I still reach over 30 million nodes per seconds or so... on a laptop...
And there's no cheat (no perft hash table, or perft approximations).

You'll certainly be able to improve the performance of your code by a fair amount, but at some point you'll reach a stage where:
1/ you realize that the same code in C# is much slower than C
2/ you have to be careful never to use any of the nice object oriented crap of C#, make sure you never trust anything that the compiler does behind your back (like exceptions, memory allocation, garbage collection)
3/ your code will become C code really, but with C# syntax. and you'll spend more time and effort coding in C# than in plain C, because of 2/

I don't think C# is a good choice for a chess engine. If you were writing a chess GUI for example, then C# would be much easier than plain C, and performance wouldn't be important, so C# would be a better choice than C.

All I can say is: rewrite it in plain C while it's not too late... And the same applies to Java, which IMO is total and utter crap
Back to top
View user's profile Send private message
Display posts from previous:   
Subject Author Date/Time
C# Performance Richard Allbert Fri Jan 27, 2012 8:41 pm
      Re: C# Performance Kevin Hearn Fri Jan 27, 2012 9:01 pm
            Re: C# Performance Richard Allbert Fri Jan 27, 2012 9:13 pm
      Re: C# Performance Gary Fri Jan 27, 2012 9:07 pm
            Re: C# Performance Richard Allbert Fri Jan 27, 2012 9:17 pm
                  Re: C# Performance Gary Fri Jan 27, 2012 10:09 pm
      Re: C# Performance Mark Pearce Sat Jan 28, 2012 12:59 am
            Re: C# Performance Richard Allbert Sat Jan 28, 2012 8:44 am
                  Re: C# Performance Sven Schüle Sat Jan 28, 2012 9:48 am
                        Re: C# Performance Richard Allbert Sat Jan 28, 2012 10:25 am
                              Re: C# Performance Richard Allbert Sat Jan 28, 2012 11:41 am
                  Re: C# Performance Mark Pearce Sat Jan 28, 2012 11:44 am
            Re: C# Performance Richard Allbert Sat Jan 28, 2012 10:31 am
      Re: C# Performance Marco Costalba Sat Jan 28, 2012 1:09 pm
            Re: C# Performance Lucas Braesch Sat Jan 28, 2012 1:52 pm
            Re: C# Performance Richard Allbert Sat Jan 28, 2012 2:05 pm
                  Re: C# Performance Marco Costalba Sat Jan 28, 2012 2:30 pm
                        Re: C# Performance Richard Allbert Sat Jan 28, 2012 5:22 pm
                              Re: C# Performance Sven Schüle Sat Jan 28, 2012 6:02 pm
                                    Re: C# Performance Richard Allbert Sat Jan 28, 2012 6:12 pm
                                    Re: C# Performance Robert Purves Sat Jan 28, 2012 10:17 pm
                              Re: C# Performance Marco Costalba Sat Jan 28, 2012 10:25 pm
                  Re: C# Performance Thomas Petzke Sat Jan 28, 2012 4:21 pm
      Re: C# Performance Richard Allbert Mon Jan 30, 2012 12:52 pm
            Re: C# Performance Marco Costalba Mon Jan 30, 2012 6:37 pm
                  Re: C# Performance Richard Allbert Wed Feb 01, 2012 6:55 pm
                        Re: C# Performance Marco Costalba Wed Feb 01, 2012 7:18 pm
            Re: C# Performance Mark Pearce Mon Jan 30, 2012 9:55 pm
                  Re: C# Performance Richard Allbert Wed Feb 01, 2012 6:57 pm
                        Re: C# Performance Mark Pearce Wed Feb 01, 2012 9:59 pm
            Re: C# Performance Mark Pearce Fri Feb 03, 2012 1:34 am
                  Re: C# Performance Robert Purves Fri Feb 03, 2012 3:26 am
                        Re: C# Performance Mark Pearce Fri Feb 03, 2012 9:28 am
                              Re: C# Performance Sven Schüle Fri Feb 03, 2012 9:45 am
                                    Re: C# Performance Mark Pearce Sat Feb 04, 2012 7:57 pm
                                          Re: C# Performance Sven Schüle Sat Feb 04, 2012 10:36 pm
                                                Re: C# Performance Mark Pearce Sat Feb 04, 2012 11:49 pm
                                                      Re: C# Performance Sven Schüle Sun Feb 05, 2012 12:51 am
                                                            Re: C# Performance Mark Pearce Sun Feb 05, 2012 1:05 am
                              Re: C# Performance Sven Schüle Fri Feb 03, 2012 10:04 am
                                    Re: C# Performance Mark Pearce Fri Feb 03, 2012 11:40 am
                                          Re: C# Performance Richard Allbert Sat Feb 04, 2012 7:10 pm
                                                Re: C# Performance Lucas Braesch Sat Feb 04, 2012 8:31 pm
                                                      Re: C# Performance Mark Pearce Sat Feb 04, 2012 10:23 pm
                                                            Re: C# Performance Mark Pearce Sun Feb 05, 2012 12:23 am
                                                                  Re: C# Performance Lucas Braesch Sun Feb 05, 2012 2:57 am
                                                                        Re: C# Performance Mark Pearce Sun Feb 05, 2012 11:40 am
                                                                              Re: C# Performance Richard Allbert Mon Feb 06, 2012 6:29 pm
                                                                                    Re: C# Performance Richard Allbert Mon Feb 06, 2012 6:29 pm
                                                                                          Re: C# Performance Richard Allbert Mon Feb 06, 2012 6:30 pm
                                                                                          Re: C# Performance Richard Allbert Mon Feb 06, 2012 6:45 pm
                                                                                          Re: C# Performance Gary Mon Feb 06, 2012 7:00 pm
                                                                                          Re: C# Performance Richard Allbert Mon Feb 06, 2012 7:12 pm
                                                                                          Re: C# Performance Sven Schüle Mon Feb 06, 2012 10:50 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:52 am
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:53 am
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:53 am
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:54 am
                                                                                          Re: C# Performance Mark Pearce Tue Feb 07, 2012 1:59 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 2:54 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 3:06 pm
                                                                                          Re: C# Performance Mark Pearce Tue Feb 07, 2012 5:17 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 6:10 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 6:20 pm
                                                                                          Re: C# Performance Mark Pearce Tue Feb 07, 2012 8:02 pm
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:19 pm
                                                                                          Re: C# Performance Mark Pearce Tue Feb 07, 2012 10:20 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 7:47 am
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 7:57 am
                                                                                          Re: C# Performance Sven Schüle Wed Feb 08, 2012 10:09 am
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 12:16 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sat Feb 18, 2012 10:03 pm
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 9:30 am
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 12:02 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 12:34 pm
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 12:56 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 1:18 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 2:30 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 2:34 pm
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 3:02 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 3:27 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 3:29 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 3:59 pm
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 4:04 pm
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 6:07 pm
                                                                                          Re: C# Performance Richard Allbert Thu Feb 09, 2012 10:41 am
                                                                                          Re: C# Performance Mark Pearce Thu Feb 09, 2012 1:47 pm
                                                                                          Re: C# Performance Richard Allbert Thu Feb 09, 2012 2:56 pm
                                                                                          Re: C# Performance Mark Pearce Sat Feb 11, 2012 4:41 pm
                                                                                          Re: C# Performance Richard Allbert Sun Feb 12, 2012 8:34 am
                                                                                          Re: C# Performance Lucas Braesch Sun Feb 12, 2012 10:52 am
                                                                                          Re: C# Performance Richard Allbert Sun Feb 12, 2012 12:26 pm
                                                                                          Re: C# Performance Ron Murawski Mon Feb 13, 2012 5:26 am
                                                                                          Re: C# Performance Lucas Braesch Mon Feb 13, 2012 5:52 am
                                                                                          Re: C# Performance Richard Allbert Mon Feb 13, 2012 6:27 am
                                                                                          Re: C# Performance Ron Murawski Tue Feb 14, 2012 6:38 am
                                                                                          Re: C# Performance Lucas Braesch Tue Feb 14, 2012 8:22 am
                                                                                          Re: C# Performance Mark Pearce Tue Feb 14, 2012 11:30 pm
                                                                                          Re: C# Performance Richard Allbert Thu Feb 16, 2012 10:49 am
                                                                                          Re: C# Performance Mark Pearce Sat Feb 18, 2012 12:34 pm
                                                                                          Re: C# Performance Richard Allbert Mon Feb 20, 2012 9:19 pm
                                                                                          Re: C# Performance Mark Pearce Tue Feb 21, 2012 8:33 am
                                                                                          Re: C# Performance Richard Allbert Tue Feb 21, 2012 6:37 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sat Feb 18, 2012 10:19 pm
                                                                                          Re: C# Performance Mark Pearce Sun Feb 12, 2012 2:01 pm
                                                                                          Re: C# Performance Richard Allbert Sun Feb 12, 2012 4:40 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sat Feb 18, 2012 10:06 pm
                                                                                          Re: C# Performance Mark Pearce Sun Feb 19, 2012 1:01 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sun Feb 19, 2012 5:25 pm
                                                                                          Re: C# Performance Mark Pearce Sun Feb 19, 2012 7:04 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sun Feb 19, 2012 9:17 pm
                                                                                          Re: C# Performance Mark Pearce Sun Feb 19, 2012 11:33 pm
                                                                                          Re: C# Performance Richard Allbert Sun Feb 19, 2012 9:22 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sun Feb 19, 2012 9:32 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sun Feb 19, 2012 9:37 pm
                                                                                          Re: C# Performance Vincent Diepeveen Sun Feb 19, 2012 10:06 pm
                                                                                          Re: C# Performance Lucas Braesch Wed Feb 08, 2012 10:56 am
                                                                                          Re: C# Performance Mark Pearce Wed Feb 08, 2012 11:30 am
                                                                                          Re: C# Performance Richard Allbert Wed Feb 08, 2012 12:04 pm
                                                                                          Re: C# Performance Tony Soares Tue Feb 07, 2012 3:47 am
                                                                                          Re: C# Performance Richard Allbert Tue Feb 07, 2012 9:55 am
                                          Re: C# Performance Mark Pearce Sat Feb 04, 2012 8:37 pm
Post new topic    TalkChess.com Forum Index -> Computer Chess Club: Programming and Technical Discussions

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2001, 2005 phpBB Group
Enhanced with Moby Threads