-
Notifications
You must be signed in to change notification settings - Fork 517
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
benchmark-test(shared-tree): Implement read/write execution time benchmark #21088
base: main
Are you sure you want to change the base?
Conversation
fc56f85
to
058e13d
Compare
356fcc8
to
9723123
Compare
/** | ||
* write the wide tree with a new value | ||
*/ | ||
export function writeWideSimpleTree(tree: WideTreeNode, newValue: number): void { | ||
const nodesCount = tree.values.length; | ||
for (let i = 0; i < nodesCount; i++) { | ||
tree.values.removeAt(i); | ||
tree.values.insertAt(i, newValue); | ||
} | ||
} |
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.
My idea of what this function needed to do to test the scenario we want is different, not replacing every node in the array, just updating the last node in the array. Because that would let us test that the cost (runtime) of doing this is more or less constant regardless of how wide the tree is, since we're just replacing one node in each case. Replacing every node in the tree could still be an interesting scenario, and we would expect it to be more expensive as the width of the tree grows, but my understanding is that we want to test replacing just one (the last) node regardless of tree width. @taylorsw04 any thoughts on this?
export function readWideSimpleTree(tree: WideTreeNode): { | ||
nodesCount: number; | ||
sum: number; | ||
} { | ||
const nodesCount = tree.values.length; | ||
let sum = 0; | ||
for (const value of tree.values) { | ||
sum += value; | ||
} | ||
return { nodesCount, sum }; | ||
} |
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.
I guess the concern in my previous comment applies to this one too. This function iterates over the whole tree, which we can reasonably expect to be more expensive as the tree grows. If instead of reading the whole tree sequentially, we did "random access" with tree.values[tree.values.length - 1], we maybe would expect constant-ish time regardless of the tree width. Again @taylorsw04 , thoughts on which case we want to test? Or both, so we can check if the increase in execution time with tree size is linear or not?
eece042
to
bca3a1d
Compare
…hmarks on simple-tree
Description
Sample