Hamming Weight

lua-users home
wiki

Showing revision 3
The hamming weight of a bitwise integer is the number of 1's in the binary representation [1].

Benchmark tests of various ways to calculate it are in [hamming_weight_test.lua]:

Lua 5.2.0/bit32, Intel Xeon, 2012-03-17
 hw_simple: 8.7E-06 8.7E-06 8.8E-06 s
    hw_pc2: 2.0E-06 2.0E-06 2.0E-06 s
     hw_t4: 1.3E-06 1.3E-06 1.3E-06 s
 hw_wegner: 4.3E-06 4.3E-06 4.2E-06 s

LuaJIT 2.x/bit git2012-03-17, Intel Xeon, 2012-03-17
 hw_simple: 1.3E-07 1.4E-07 1.3E-07 s
    hw_pc2: 2.4E-09 2.4E-09 2.4E-09 s
     hw_t4: 8.4E-08 8.4E-08 8.4E-08 s
 hw_wegner: 7.4E-08 7.3E-08 7.4E-08 s

(smaller is better)

See Also


RecentChanges · preferences
edit · history · current revision
Edited March 21, 2012 7:08 pm GMT (diff)