简体   繁体   中英

Slow ulong bitwise AND in C#

I'm trying to optimize my chess program. I'm using ulong bitboards to generate legal moves as I thought it would be very quick. Profiler, however, suggests that much of the time is spent on bitwise AND operation (over 20% of inclusive samples, as shown below; analysis performed several times with the same result).

The profiled code was optimized x64, ran on VMWare Player (Windows 7 guest, Debian host). I couldn't get Mono Profiler to work to see if it produces the same results, but Mono executed natively on Linux ran code exactly the same time as .Net framework on VMWare.

Can the report shown below possibly be correct and the operation is indeed that heavy, am I misinterpreting it, or is the profiler inaccurate?

分析结果

It turns out to be a profiler inaccuracy. I moved the line above the AND operation ( ulong movesBitboard = ... ) to some other location and now this line is marked as taking over 20% of samples - and that result is perfectly reasonable.

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