-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verkle: Add tests for verkle bytes helper #3441
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,47 @@ | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import { matchingBytesLength } from '../../src/util/bytes.js' | ||
|
||
describe('matchingBytesLength', () => { | ||
it('should return 0 when both arrays are empty', () => { | ||
const bytes1 = new Uint8Array([]) | ||
const bytes2 = new Uint8Array([]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 0) | ||
}) | ||
|
||
it('should return 0 when one of the arrays is empty', () => { | ||
const bytes1 = new Uint8Array([1, 2, 3]) | ||
const bytes2 = new Uint8Array([]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 0) | ||
}) | ||
|
||
it('should return 0 when arrays have no matching elements', () => { | ||
const bytes1 = new Uint8Array([1, 2, 3]) | ||
const bytes2 = new Uint8Array([4, 5, 6]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 0) | ||
}) | ||
|
||
it('should handle arrays with same elements but different lengths', () => { | ||
const bytes1 = new Uint8Array([1, 2, 3]) | ||
const bytes2 = new Uint8Array([1, 2, 3, 4]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 3) | ||
}) | ||
|
||
it('should handle arrays with matching elements at end', () => { | ||
const bytes1 = new Uint8Array([1, 2, 3]) | ||
const bytes2 = new Uint8Array([0, 1, 2, 3]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 0) | ||
}) | ||
|
||
it('should handle arrays with matching elements at start', () => { | ||
const bytes1 = new Uint8Array([1, 2, 3]) | ||
const bytes2 = new Uint8Array([1, 2, 3, 4, 5]) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 3) | ||
}) | ||
|
||
it('should handle arrays with large number of elements', () => { | ||
const bytes1 = new Uint8Array(Array.from({ length: 1000000 }, (_, i) => i)) | ||
const bytes2 = new Uint8Array(Array.from({ length: 1000000 }, (_, i) => i)) | ||
assert.equal(matchingBytesLength(bytes1, bytes2), 1000000) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do performance testing to show that this is faster? It's not obvious to me why this is any faster than iterating element by element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the benchmark file is in the above comment: #3441 (comment). Since multiple bytes are being compared at a time, the loop runs less times and handles the remaining comparisons outside of the first loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, didn't see this. Thanks for the comparison!