Benchmarks
Measuring performance to find out how fast Results are
Last updated
Was this helpful?
Measuring performance to find out how fast Results are
Last updated
Was this helpful?
Throughout these guides, we have mentioned that throwing Java exceptions is slow. But... how slow? According to our benchmarks, throwing an exception is several orders of magnitude slower than returning a failed result.
This proves that using exceptional logic just to control normal program flow is a bad idea.
The first scenarios compare the most basic usage: a method that returns a String
or fails, depending on a given int
parameter:
The next scenarios do something a little bit more elaborate: a method invokes the previous method to retrieve a String
; if successful, then converts it to upper case; otherwise transforms the "simple" error into a "complex" error.
We provided insights into the Result library's performance through benchmarking. While our metrics corroborate that most codebases could benefit from using this library instead of throwing exceptions, its main goal is to help promote best practices and implement proper error handling.
This library comes with when using results versus when using exceptions.