| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 new BenchmarkSuite('Closures', [1000], [ | |
| 6 new Benchmark('ShortLivingClosures', false, false, 0, | |
| 7 ShortLivingClosures, ShortLivingClosuresSetup, ShortLivingClosuresTearDown) | |
| 8 ]); | |
| 9 | |
| 10 // ---------------------------------------------------------------------------- | |
| 11 | |
| 12 | |
| 13 // The pattern is this example is very common in Node.js. | |
| 14 var fs = { | |
| 15 readFile: function(filename, cb) { | |
| 16 cb(null, {length: 12}); | |
| 17 } | |
| 18 }; | |
| 19 | |
| 20 | |
| 21 function printLength (filename) { | |
| 22 fs.readFile(filename, foo); | |
| 23 | |
| 24 function foo (err, buf) { | |
| 25 if (err) return; | |
| 26 for (var j = 0; j<1000; j++) { | |
| 27 // Do some work to make the optimization actually worth while | |
| 28 buf.length++; | |
| 29 } | |
| 30 return (buf.length); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 | |
| 35 function ShortLivingClosuresSetup() {} | |
| 36 | |
| 37 function ShortLivingClosures() { | |
| 38 result = printLength('foo_bar.js'); | |
| 39 } | |
| 40 | |
| 41 function ShortLivingClosuresTearDown() { | |
| 42 return result == 1012; | |
| 43 } | |
| OLD | NEW |