Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
Added another bitops test from SunSpider.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Dec 3, 2008
1 parent e7f4368 commit cabdeb5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/MANIFEST.json
Expand Up @@ -143,6 +143,14 @@
category: "SunSpider JavaScript Tests",
tags: ["looping", "bitops"]
},
"sunspider-bitops-bits-in-byte": {
file: "sunspider-bitops-bits-in-byte.js",
name: "Compute Bits in Byte (2)",
origin: ["SunSpider", "http://www2.webkit.org/perf/sunspider-0.9/sunspider.html"],
desc: "Compute the number of bits in a number using bitops.",
category: "SunSpider JavaScript Tests",
tags: ["looping", "bitops"]
},
"sunspider-bitops-nsieve-bits": {
file: "sunspider-bitops-nsieve-bits.js",
name: "Prime Number Computation (2)",
Expand Down
31 changes: 31 additions & 0 deletions tests/sunspider-bitops-bits-in-byte.js
@@ -0,0 +1,31 @@
// Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com)


// 1 op = 2 assigns, 16 compare/branches, 8 ANDs, (0-8) ADDs, 8 SHLs
// O(n)
function bitsinbyte(b) {
var m = 1, c = 0;
while(m<0x100) {
if(b & m) c++;
m <<= 1;
}
return c;
}

function TimeFunc(func) {
var x, y, t;
for(var x=0; x<100; x++)
for(var y=0; y<256; y++) func(y);
}

startTest("sunspider-bitops-bits-in-byte");

for ( var i = 0; i < 4; i++ ) {

test("Bit in byte (2)", i, function(){
TimeFunc(bitsinbyte);
});

}

endTest();

0 comments on commit cabdeb5

Please sign in to comment.