diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2025-08-18 03:59:02 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2025-08-18 03:59:02 +0200 |
commit | dd775090878854ccfe65310f9457ce3e393c070d (patch) | |
tree | e942c0bc0e96e0eb170dfbcbe8d63a7635bba57a /test/benchmarks/bit_count1.c | |
parent | 177a172719f065dd32ea1217bfb35d6b640d0bad (diff) |
Diffstat (limited to 'test/benchmarks/bit_count1.c')
-rwxr-xr-x | test/benchmarks/bit_count1.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/benchmarks/bit_count1.c b/test/benchmarks/bit_count1.c new file mode 100755 index 0000000..c900524 --- /dev/null +++ b/test/benchmarks/bit_count1.c @@ -0,0 +1,30 @@ +/* + * Bit counter by Ratko Tomic + */ + +long atol(char *); +int printf(char *s, ...); + +int bit_count(long x) +{ + int n = 0; + if (x) do + n++; + while (0 != (x = x&(x-1))) ; + return(n); +} + +int main(int argc, char **argv) +{ + long n = atol(*++argv); + long i; + int sum = 0; + + if (n == 0) + return 1; + + for (i = 0; i < n; ++i) + sum += bit_count(i); + printf("%d\n", sum); + return 0; +} |