Commit c0973156 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[test] Use binary search for max expression depth

Use an upper limit search followed by a binary search in the expression
depth test. As our maximum expression depths increase, a simple linear
search wastes cycles.

Bug: v8:6964
Change-Id: I0669e4090f6cc1628d1dec475b9bd8ff52be3f7d
Reviewed-on: https://chromium-review.googlesource.com/735346
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48919}
parent f3b4841d
...@@ -35,18 +35,43 @@ function TestExpressionDepth(depth, expression, prologue, epilogue) { ...@@ -35,18 +35,43 @@ function TestExpressionDepth(depth, expression, prologue, epilogue) {
} }
function RunTest(name, expression, prologue, epilogue) { function RunTest(name, expression, prologue, epilogue) {
var depth; var low_depth = 0;
var high_depth = 1;
// Find the upper limit where depth breaks down.
try { try {
for (depth = 0; depth < 20000; depth += 100) { while (high_depth <= 65536) {
TestExpressionDepth(depth, expression, prologue, epilogue); TestExpressionDepth(high_depth, expression, prologue, epilogue);
low_depth = high_depth;
high_depth *= 4;
} }
// Looks like we can't get the depth to break down, just report
// the maximum depth tested.
print(name + '-ExpressionDepth(Score): ' + low_depth);
return;
} catch (e) { } catch (e) {
if (!e instanceof RangeError) { if (!e instanceof RangeError) {
print(name + '-ExpressionDepth(Score): ERROR'); print(name + '-ExpressionDepth(Score): ERROR');
return; return;
} }
} }
print(name + '-ExpressionDepth(Score): ' + depth);
// Binary search the actual limit.
while (low_depth + 1 < high_depth) {
var mid_depth = Math.round((low_depth + high_depth) / 2);
try {
TestExpressionDepth(mid_depth, expression, prologue, epilogue);
low_depth = mid_depth;
} catch (e) {
if (!e instanceof RangeError) {
print(name + '-ExpressionDepth(Score): ERROR');
return;
}
high_depth = mid_depth;
}
}
print(name + '-ExpressionDepth(Score): ' + low_depth);
} }
function AddTest(name, expression, in_test) { function AddTest(name, expression, in_test) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment