| // Copyright 2017 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 |
| // Flags: --allow-natives-syntax --expose-gc |
| new BenchmarkSuite('ManyClosures', [1000], [ |
| new Benchmark('CreateManyClosures', false, true, 1, CreateManyClosures, |
| CreateManyClosures_Setup) |
| // ---------------------------------------------------------------------------- |
| // This program creates many closures and then allocates many arrays in order |
| // to trigger garbage collection cycles. The goal of this micro-benchmark is to |
| // evaluate the overhead of keeping the weak-list of optimized JS functions. |
| // c.f. https://bugs.chromium.org/p/v8/issues/detail?id=6637#c5 |
| %NeverOptimizeFunction(CreateManyClosures_Setup); |
| function CreateManyClosures_Setup() { |
| // Create a closure and optimize. |
| %PrepareFunctionForOptimization(f); |
| %OptimizeFunctionOnNextCall(f); |
| // Create 2M closures, those will get the optimized code. |
| for (var i = 0; i < 2000000; i++) { |
| %NeverOptimizeFunction(CreateManyClosures); |
| function CreateManyClosures() { |
| for (var i = 0; i < 50; i++) { |