Most efficient way to calculate hamming distance in ruby?

前端 未结 4 1634
予麋鹿
予麋鹿 2020-12-30 06:06

In ruby, what is the most efficient way to calculate the bit difference between two unsigned integers (e.g. the hamming distance)?

Eg, I have integer a = 2323409845

4条回答
  •  温柔的废话
    2020-12-30 06:21

    If one intends to follow c-based path, it is a good idea to add the compiler flag -msse4.2 to your makefile. This allows the compiler to generate hardware based popcnt instructions instead of using a table to generate the popcount. On my system this was approximately 2.5x faster.

提交回复
热议问题