OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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('Filter', [1000], [ |
| 6 new Benchmark('SmiFilter', false, false, 0, |
| 7 Filter, SmiFilterSetup, ()=>{}), |
| 8 new Benchmark('DoubleFilter', false, false, 0, |
| 9 Filter, DoubleFilterSetup, ()=>{}), |
| 10 new Benchmark('FastFilter', false, false, 0, |
| 11 Filter, FastFilterSetup, ()=>{}), |
| 12 new Benchmark('HoleySmiFilter', false, false, 0, |
| 13 Filter, HoleySmiFilterSetup, ()=>{}), |
| 14 new Benchmark('HoleyDoubleFilter', false, false, 0, |
| 15 Filter, HoleyDoubleFilterSetup, ()=>{}), |
| 16 new Benchmark('HoleyFastFilter', false, false, 0, |
| 17 Filter, HoleyFastFilterSetup, ()=>{}), |
| 18 new Benchmark('ObjectFilter', false, false, 0, |
| 19 GenericFilter, ObjectFilterSetup, ()=>{}), |
| 20 ]); |
| 21 |
| 22 var array; |
| 23 var func; |
| 24 var this_arg; |
| 25 var result; |
| 26 var array_size = 100; |
| 27 |
| 28 function Filter() { |
| 29 result = array.filter(func, this_arg); |
| 30 } |
| 31 |
| 32 function GenericFilter() { |
| 33 result = Array.prototype.filter.call(array, func, this_arg); |
| 34 } |
| 35 |
| 36 function SmiFilterSetup() { |
| 37 array = new Array(); |
| 38 for (var i = 0; i < array_size; i++) array[i] = i; |
| 39 func = (value, index, object) => { return value % 2 === 0; }; |
| 40 } |
| 41 |
| 42 function HoleySmiFilterSetup() { |
| 43 array = new Array(array_size); |
| 44 for (var i = 0; i < array_size; i++) { |
| 45 if (i % 2 === 0) array[i] = i; |
| 46 } |
| 47 func = (value, index, object) => { return value % 2 === 0; }; |
| 48 } |
| 49 |
| 50 function DoubleFilterSetup() { |
| 51 array = new Array(); |
| 52 for (var i = 0; i < array_size; i++) array[i] = (i + 0.5); |
| 53 func = (value, index, object) => { return Math.floor(value) % 2 === 0; }; |
| 54 } |
| 55 |
| 56 function HoleyDoubleFilterSetup() { |
| 57 array = new Array(array_size); |
| 58 for (var i = 0; i < array_size; i++) { |
| 59 if (i != 3) { |
| 60 array[i] = (i + 0.5); |
| 61 } |
| 62 } |
| 63 func = (value, index, object) => { return Math.floor(value) % 2 === 0; }; |
| 64 } |
| 65 |
| 66 function FastFilterSetup() { |
| 67 array = new Array(); |
| 68 for (var i = 0; i < array_size; i++) array[i] = 'value ' + i; |
| 69 func = (value, index, object) => { return index % 2 === 0; }; |
| 70 } |
| 71 |
| 72 function HoleyFastFilterSetup() { |
| 73 array = new Array(array_size); |
| 74 for (var i = 0; i < array_size; i++) { |
| 75 if (i % 2 != 0) { |
| 76 array[i] = 'value ' + i; |
| 77 } |
| 78 } |
| 79 func = (value, index, object) => { return index % 2 === 0; }; |
| 80 } |
| 81 |
| 82 function ObjectFilterSetup() { |
| 83 array = { length: array_size }; |
| 84 for (var i = 0; i < array_size; i++) { |
| 85 array[i] = i; |
| 86 } |
| 87 func = (value, index, object) => { return index % 2 === 0; }; |
| 88 } |
OLD | NEW |