From dd775090878854ccfe65310f9457ce3e393c070d Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Mon, 18 Aug 2025 03:59:02 +0200 Subject: Benchmark files --- test/benchmarks/bit_count1.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 test/benchmarks/bit_count1.c (limited to 'test/benchmarks/bit_count1.c') 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; +} -- cgit v1.2.3