v8/test/js-perf-test/Closures/closures.js
franzih 82061d6ab3 [test] Add performance test for closures.
Short living closures are very common in Node.js. This benchmark tracks progress
as we move the optimizations that are currently only behind
--mark_shared_functions_for_tier_up to the default settings.

BUG=v8:5512

Committed: https://crrev.com/f277da2a00cfd27d44a33a70213a65bd82d0bc95
Review-Url: https://codereview.chromium.org/2525053002
Cr-Original-Commit-Position: refs/heads/master@{#41246}
Cr-Commit-Position: refs/heads/master@{#41487}
2016-12-05 13:10:44 +00:00

44 lines
1.0 KiB
JavaScript

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
new BenchmarkSuite('Closures', [1000], [
new Benchmark('ShortLivingClosures', false, false, 0,
ShortLivingClosures, ShortLivingClosuresSetup, ShortLivingClosuresTearDown)
]);
// ----------------------------------------------------------------------------
// The pattern is this example is very common in Node.js.
var fs = {
readFile: function(filename, cb) {
cb(null, {length: 12});
}
};
function printLength (filename) {
fs.readFile(filename, foo);
function foo (err, buf) {
if (err) return;
for (var j = 0; j<1000; j++) {
// Do some work to make the optimization actually worth while
buf.length++;
}
return (buf.length);
}
}
function ShortLivingClosuresSetup() {}
function ShortLivingClosures() {
result = printLength('foo_bar.js');
}
function ShortLivingClosuresTearDown() {
return result == 1012;
}