Linked Questions
13 questions linked to/from Which part of throwing an Exception is expensive?
-1
votes
1
answer
243
views
Is constructing an exception slower than constructing an exception supplier? [duplicate]
Why do we have to write it like so? Is creating an exception instance more expensive than creating a supplier instance?
var value = getOptional().orElseThrow(NullPointerException::new);
// instead of
...
994
votes
11
answers
150k
views
How do I write a correct micro-benchmark in Java?
How do you write (and run) a correct micro-benchmark in Java?
I'm looking for some code samples and comments illustrating various things to think about.
Example: Should the benchmark measure time/...
229
votes
7
answers
67k
views
Is it expensive to use try-catch blocks even if an exception is never thrown?
We know that it is expensive to catch exceptions. But, is it also expensive to use a try-catch block in Java even if an exception is never thrown?
I found the Stack Overflow question/answer Why are ...
23
votes
4
answers
17k
views
How to disable compiler and JVM optimizations?
I have this code that is testing Calendar.getInstance().getTimeInMillis() vs System.currentTimeMilli() :
long before = getTimeInMilli();
for (int i = 0; i < TIMES_TO_ITERATE; i++)
{
long before1 ...
13
votes
4
answers
2k
views
Exceptions catching performance in python
I know exceptions in python are fast when it comes to the try but that it may be expensive when it comes to the catch.
Does this mean that:
try:
some code
except MyException:
pass
is faster ...
4
votes
1
answer
4k
views
Why does the `orElseThrow()` method in Java take a `Supplier` as a parameter instead of an `Exception`?
Why does the orElseThrow() method in Java take a Supplier as a parameter instead of an Exception? This is the question and the best answer I have found is in here, stating
The overarching concept ...
6
votes
3
answers
129
views
Using try-catch over if conditions to safely set values with minimum performance impact in java
Here, my main goal is setting the value safely, without having a performance (speed, memory, cpu etc) impact.
I have a silly option (in a bad style) also mentioned below.
So, what is the best way to ...
3
votes
2
answers
2k
views
Is it normal that Amazon AWS Lambda Java functions take an unreasonable long time to finish when an uncaught exception is thrown?
Is it normal that any Amazon AWS Lambda Java function takes an unreasonable long time to finish when an uncaught exception is thrown? Please note this is a general question regarding Amazon Lambdas in ...
0
votes
1
answer
3k
views
Understanding Java's stack unwinding on thrown exception
During a discussion and some research regarding using exceptions vs returning values, the following caught my mind:
It is cheaper and provides better performance to return a value, whereas throwing ...
0
votes
4
answers
1k
views
Check if a String does not only contain integers
I am trying to execute a block of code on a String if it does not contain only integers. For example, if input is 2017, nothing will happen; else if it's 2017abc, the block of code will be executed.
...
0
votes
1
answer
280
views
Determine if an XPath query is valid
Is there a method in Saxon, or another library, that will tell me if an XPath query is valid syntax. Not if it will return something, not if the nodes exist in an XML file, but if it's valid syntax.
...
0
votes
3
answers
289
views
Reading a file -- pairing a String and int value -- with multiple split lines
I am working on an exercise with the following criteria:
"The input consists of pairs of tokens where each pair begins with the type of ticket that the person bought ("coach", "...
0
votes
0
answers
61
views
In Java, does validating user input with a while loop take a lot of processing time/resources [duplicate]
So while editing my question (multiple attempts) I finally found the correct search terms for my original question (see below - I was missing the try-catch part).
Answers I was searching for:
Is it ...