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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Try finally
34699.4 Ops/sec
Without try finally
34643.2 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([])