-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize getSlotFromOffset (#6941)
* chore: optimize getSlotFromOffset * chore: add perf test
- Loading branch information
1 parent
514b605
commit a0f2dcc
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {itBench} from "@dapplion/benchmark"; | ||
|
||
describe("dataview", function () { | ||
const data = Uint8Array.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); | ||
|
||
itBench({ | ||
id: "getUint32 - dataview", | ||
beforeEach: () => { | ||
return 0; | ||
}, | ||
fn: (offset) => { | ||
const view = new DataView(data.buffer, data.byteOffset, data.byteLength); | ||
view.getUint32(offset, true); | ||
}, | ||
}); | ||
|
||
itBench({ | ||
id: "getUint32 - manual", | ||
beforeEach: () => { | ||
return 0; | ||
}, | ||
fn: (offset) => { | ||
// check high bytes for non-zero values | ||
(data[offset + 4] | data[offset + 5] | data[offset + 6] | data[offset + 7]) === 0; | ||
// create the uint32 | ||
(data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24)) >>> 0; | ||
}, | ||
}); | ||
}); |
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