Created
March 28, 2023 08:31
-
-
Save JobLeonard/0b439a845c6d5822a2923b5affbd7b36 to your computer and use it in GitHub Desktop.
Bit Array fill test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"title":"Bit Array fill test","initialization":"// runs once\nclass BitArray1 {\n constructor(length) {\n this.bits32 = new Uint32Array(Math.ceil(length / 32));\n this.bits = new Uint8Array(this.bits32.buffer);\n this.length = length;\n }\n\n fill(bool) {\n this.bits32.fill(bool ? 0xFFFFFFFF : 0);\n }\n\n set(i) {\n this.bits[i >> 3] |= (1 << (i & 7));\n }\n\n unset(i) {\n this.bits[i >> 3] &= 255 - (1 << (i & 7));\n }\n\n at(i) {\n return (this.bits[i >> 3] & (1 << (i & 7))) ? true : false;\n }\n\n [Symbol.iterator]() {\n let i = 0;\n const {bits, length} = this;\n return {\n next(){\n if (i < length) {\n const v = {\n done: false,\n value: bits[i >> 3] & (1 << (i & 7)) ? true : false\n };\n i++;\n return v;\n }\n return {done: true, value: undefined};\n }\n };\n }\n}\n\nclass BitArray2 {\n constructor(length) {\n this.bits = new Uint8Array(Math.ceil(length / 8));\n this.length = length;\n }\n\n fill(bool) {\n this.bits.fill(bool ? 255 : 0);\n }\n\n set(i) {\n this.bits[i >> 3] |= (1 << (i & 7));\n }\n\n unset(i) {\n this.bits[i >> 3] &= 255 - (1 << (i & 7));\n }\n\n at(i) {\n return (this.bits[i >> 3] & (1 << (i & 7))) ? true : false;\n }\n\n [Symbol.iterator]() {\n let i = 0;\n const {bits, length} = this;\n return {\n next(){\n if (i < length) {\n const v = {\n done: false,\n value: bits[i >> 3] & (1 << (i & 7)) ? true : false\n };\n i++;\n return v;\n }\n return {done: true, value: undefined};\n }\n };\n }\n}","setup":"// runs before each test\nconst bitArr1 = new BitArray1(1000000);\nconst bitArr2 = new BitArray2(1000000);","tests":[{"name":"test 1","code":"// put test code here\nbitArr1.fill(true);","results":{"aborted":false,"count":2304,"cycles":6,"hz":29650.44350661102,"stats":{"moe":3.5838947086431036e-7,"rme":1.062640675922645,"sem":1.8285177084913794e-7,"deviation":0.0000014854948087340909,"mean":0.00003372630833589503,"variance":2.2066948267759335e-12,"numSamples":66},"times":{"cycle":0.07770541440590216,"elapsed":6.159,"period":0.00003372630833589503,"timeStamp":1679992256437}},"platforms":{"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0":{"aborted":false,"count":2304,"cycles":6,"hz":29650.44350661102,"stats":{"moe":3.5838947086431036e-7,"rme":1.062640675922645,"sem":1.8285177084913794e-7,"deviation":0.0000014854948087340909,"mean":0.00003372630833589503,"variance":2.2066948267759335e-12,"numSamples":66},"times":{"cycle":0.07770541440590216,"elapsed":6.159,"period":0.00003372630833589503,"timeStamp":1679992256437}}}},{"name":"test 2","code":"// put test code here\nbitArr2.fill(true);","results":{"aborted":false,"count":938,"cycles":3,"hz":8139.596302584422,"stats":{"moe":0.000004564683760180107,"rme":3.715468305682916,"sem":0.0000023289202858061772,"deviation":0.000015795505882731905,"mean":0.0001228562158153332,"variance":2.494980060914182e-10,"numSamples":46},"times":{"cycle":0.11523913043478255,"elapsed":5.782,"period":0.0001228562158153332,"timeStamp":1679992262601}},"platforms":{"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0":{"aborted":false,"count":938,"cycles":3,"hz":8139.596302584422,"stats":{"moe":0.000004564683760180107,"rme":3.715468305682916,"sem":0.0000023289202858061772,"deviation":0.000015795505882731905,"mean":0.0001228562158153332,"variance":2.494980060914182e-10,"numSamples":46},"times":{"cycle":0.11523913043478255,"elapsed":5.782,"period":0.0001228562158153332,"timeStamp":1679992262601}}}}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment