Ad
  • Custom User Avatar
  • Default User Avatar

    It is a smart solution, because it uses the standard library, but one of the slowest ones.
    It creates an unnecessary temporary object with significant overhead.
    Overal solution is 1.5 times slower than a table lookup algorithm and 2.5 times slower than parallel bits counting algorithm.

    I would not recommend it as a best practices.

  • Default User Avatar

    On my Core i7-4770K best performance is obviously using popcnt instruction, but this one is the next best. The most recommended solution with bitset has the worst performance so far.

    CPU clocks per item calculated:
    popcnt 2.7
    parallel bits counting 6.2
    lookup table 11.0
    std::bitset 16.3