Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created October 16, 2016 14:22
Show Gist options
  • Select an option

  • Save fcamel/7ee4127eda7bfed9e3fd08820eb9dc93 to your computer and use it in GitHub Desktop.

Select an option

Save fcamel/7ee4127eda7bfed9e3fd08820eb9dc93 to your computer and use it in GitHub Desktop.
$ g++ -std=c++11 count_bits.cpp -o count_bits -O3 && ./count_bits
count_directly : sum=7998166000, duration=3315520721 ns
count_by_table : sum=7998166000, duration=607687929 ns
count_by_table8 : sum=7998166000, duration=694708929 ns
count_by_bit_operation: sum=7998166000, duration=241576894 ns
count_by_popcnt : sum=7998166000, duration=69186289 ns
@arcbbb
Copy link

arcbbb commented Oct 17, 2016

Thanks for your article that shares this experiment. The algorithm of bit operation is amazing and impressive.
It is interesting that count_by_table8 is no faster than count_by_table in your result, since the table size are greatly reduced and should fit data cache well.
Then I did the same experiment on my laptop.
Here is my result https://gist.github.com/arcbbb/634323d2295a4beab1c080e0dc7bc2af
just to share the information with you that my laptop shows different result. quite interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment