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