OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 new BenchmarkSuite('Try-Catch', [1000], [ | 5 new BenchmarkSuite('Try-Catch', [1000], [ |
6 new Benchmark('OnSuccess', false, false, 0, | 6 new Benchmark('OnSuccess', false, false, 0, |
7 OnSuccess, OnSuccessSetup, | 7 OnSuccess, OnSuccessSetup, |
8 OnSuccessTearDown), | 8 OnSuccessTearDown), |
9 new Benchmark('OnException', false, false, 0, | 9 new Benchmark('OnException', false, false, 0, |
10 OnException, OnExceptionSetup, | 10 OnException, OnExceptionSetup, |
11 OnExceptionTearDown), | 11 OnExceptionTearDown), |
12 new Benchmark('OnSuccessFinallyOnly', false, false, 0, | 12 new Benchmark('OnSuccessFinallyOnly', false, false, 0, |
13 OnSuccessFinallyOnly, OnSuccessFinallyOnlySetup, | 13 OnSuccessFinallyOnly, OnSuccessFinallyOnlySetup, |
14 OnSuccessFinallyOnlyTearDown), | 14 OnSuccessFinallyOnlyTearDown), |
15 new Benchmark('WithFinallyOnException', false, false, 0, | 15 new Benchmark('WithFinallyOnException', false, false, 0, |
16 WithFinallyOnException, WithFinallyOnExceptionSetup, WithFinally
OnExceptionTearDown) | 16 WithFinallyOnException, WithFinallyOnExceptionSetup, |
| 17 WithFinallyOnExceptionTearDown) |
17 ]); | 18 ]); |
18 | 19 |
19 var a; | 20 var a; |
20 var b; | 21 var b; |
21 var c; | 22 var c; |
22 | 23 |
23 // ---------------------------------------------------------------------------- | 24 // ---------------------------------------------------------------------------- |
24 | 25 |
25 function OnSuccessSetup() { | 26 function OnSuccessSetup() { |
26 var a = 4; | 27 a = 4; |
27 var b = 6; | 28 b = 6; |
28 var c = 0; | 29 c = 0; |
29 } | 30 } |
30 | 31 |
31 function OnSuccess() { | 32 function OnSuccess() { |
32 try { | 33 try { |
33 c = a + b; | 34 c = a + b; |
34 } | 35 } |
35 catch (e) { | 36 catch (e) { |
| 37 c++; |
36 } | 38 } |
37 } | 39 } |
38 | 40 |
39 function OnSuccessTearDown() { | 41 function OnSuccessTearDown() { |
40 return c === 10; | 42 return c === 10; |
41 } | 43 } |
42 | 44 |
43 // ---------------------------------------------------------------------------- | 45 // ---------------------------------------------------------------------------- |
44 | 46 |
45 function OnExceptionSetup() { | 47 function OnExceptionSetup() { |
46 var a = 4; | 48 a = 4; |
47 var b = 6; | 49 b = 6; |
48 var c = 0; | 50 c = 0; |
49 } | 51 } |
50 | 52 |
51 function OnException() { | 53 function OnException() { |
52 try { | 54 try { |
53 throw 'Test exception'; | 55 throw 'Test exception'; |
54 } | 56 } |
55 catch (e) { | 57 catch (e) { |
56 c = a + b; | 58 c = a + b; |
57 } | 59 } |
58 } | 60 } |
59 | 61 |
60 function OnExceptionTearDown() { | 62 function OnExceptionTearDown() { |
61 return c === 10; | 63 return c === 10; |
62 } | 64 } |
63 | 65 |
64 // ---------------------------------------------------------------------------- | 66 // ---------------------------------------------------------------------------- |
65 | 67 |
66 function OnSuccessFinallyOnlySetup() { | 68 function OnSuccessFinallyOnlySetup() { |
67 var a = 4; | 69 a = 4; |
68 var b = 6; | 70 b = 6; |
69 var c = 0; | 71 c = 0; |
70 } | 72 } |
71 | 73 |
72 function OnSuccessFinallyOnly() { | 74 function OnSuccessFinallyOnly() { |
73 try { | 75 try { |
74 c = a + b; | 76 c = a + b; |
75 } | 77 } |
76 finally { | 78 finally { |
77 c++; | 79 c++; |
78 } | 80 } |
79 } | 81 } |
80 | 82 |
81 function OnSuccessFinallyOnlyTearDown() { | 83 function OnSuccessFinallyOnlyTearDown() { |
82 return c === 11; | 84 return c === 11; |
83 } | 85 } |
84 | 86 |
85 // ---------------------------------------------------------------------------- | 87 // ---------------------------------------------------------------------------- |
86 | 88 |
87 function WithFinallyOnExceptionSetup() { | 89 function WithFinallyOnExceptionSetup() { |
88 var a = 4; | 90 a = 4; |
89 var b = 6; | 91 b = 6; |
90 var c = 0; | 92 c = 0; |
91 } | 93 } |
92 | 94 |
93 function WithFinallyOnException() { | 95 function WithFinallyOnException() { |
94 try { | 96 try { |
95 throw 'Test exception'; | 97 throw 'Test exception'; |
96 } | 98 } |
97 catch (e) { | 99 catch (e) { |
98 c = a + b; | 100 c = a + b; |
99 } | 101 } |
100 finally { | 102 finally { |
101 c++; | 103 c++; |
102 } | 104 } |
103 } | 105 } |
104 | 106 |
105 function WithFinallyOnExceptionTearDown() { | 107 function WithFinallyOnExceptionTearDown() { |
106 return c === 11; | 108 return c === 11; |
107 } | 109 } |
108 // ---------------------------------------------------------------------------- | 110 // ---------------------------------------------------------------------------- |
OLD | NEW |