Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Try/finally performance impact
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Try finally
110344.9 Ops/sec
Without try finally
110362.8 Ops/sec
Script Preparation code:
function function_with_try_finally(array) { try { array.push(Math.random() * 1000000) array.push(Math.random() * 1000000) // Simulating some workload let sum = 0 for (let i = 0; i < 100; i++) { for (let j = 0; j < i; j++) { sum += j * j } } // Randomly deciding whether to exit early if (Math.random() < 0.3) { return sum } // More workload for (let i = 0; i < 1000; i++) { for (let j = 0; j < 10; j++) { sum += j * j } } // Another random exit point if (Math.random() < 0.6) { return sum } if (array.length < 500) { function_with_try_finally(array) return 0 } } finally { // Cleanup action: array.pop() array.pop() } return -1 } function function_with_explicit_cleanup(array) { array.push(Math.random() * 1000000) array.push(Math.random() * 1000000) // Simulating some workload let sum = 0 for (let i = 0; i < 100; i++) { for (let j = 0; j < i; j++) { sum += j * j } } // Randomly deciding whether to exit early if (Math.random() < 0.3) { array.pop() return sum } // More workload for (let i = 0; i < 1000; i++) { for (let j = 0; j < 10; j++) { sum += j * j } } // Another random exit point if (Math.random() < 0.6) { array.pop() return sum } if (array.length < 500) { function_with_try_finally(array) array.pop() return 0 } // Cleanup action: array.pop() array.pop() return -1 }
Tests:
Try finally
function_with_try_finally([])
Without try finally
function_with_explicit_cleanup([])