简体   繁体   中英

Bit manipulation on uint64_t or std::bitset

I want to write a chess engine and I've decided to use the bitboard representation of the board. I've done some reading and I found out that the most efficient way to do it is to use 64-bit long variables and bit manipulation. However I also know that there is a thing called std::bitset which, if my understanding is correct, does exactly the thing I need it to.

My question is: Is it better to use the std::bitset in order to have code that is a little slower but easier to read and write or is it better to focus solely on the performance?

Since your question is about performance and readability, I suggest you listen to Herb Sutter's speech @ CppCon 2014 here .

In a nutshell:

  • Write for clarity and correctness first.
  • Avoid premature optimization (prefer clear code over optimized code).

I don't think memory optimization is a concern for a chess program IMHO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM