Skip to content

Commit

Permalink
Add a benchmark exercising property lookups in the immediate prototype.
Browse files Browse the repository at this point in the history
Summary:
This diff adds a microbenchmark stressing property lookups satisfied
in an object's immediate prototype.  This provides a baseline for a
subsequent diff that optimizes such accesses.

Reviewed By: avp

Differential Revision: D65350534

fbshipit-source-id: 12b1dfdfbc7219d0427b64ca944c7f94d0079368
  • Loading branch information
David Detlefs authored and facebook-github-bot committed Jan 17, 2025
1 parent 5943fa4 commit 685b9b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions benchmarks/bench-runner/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def __repr__(self):
"numberArrayReadWrite", "micros/numberArrayReadWrite.js",
gcMinHeap="1M", gcMaxHeap="1M"
),
ResourceBenchmark(
"protoCache", "micros/protoCache.js",
gcMinHeap="1M", gcMaxHeap="1M"
),
],
runByDefault=False,
)
Expand Down
29 changes: 29 additions & 0 deletions benchmarks/bench-runner/resource/test-suites/micros/protoCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var start = new Date();
var val = (function () {
var proto = {x: 7};
var o = Object.create(proto);

function access(o) {
'noinline'
// 50 accesses, all found in the proto.
return o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x
+ o.x + o.x + o.x + o.x + o.x;
}
var numIter = 10000000;
var sum = 0;
for (var i = 0; i < numIter; i++) {
sum += access(o);
}
return sum;
}());
var end = new Date();
print("val: " + val);
print("Time: " + (end - start));

0 comments on commit 685b9b0

Please sign in to comment.