Skip to content

Compare performance of if/else vs try/catch #1114

@popematt

Description

@popematt

We should test whether it is faster, in the happy case, to check things like array bounds, or to just catch and rethrow IonException. Catching and rethrowing is slower in the error case, but we're not as concerned about the performance for error cases. In the happy case, it might be faster because we eliminate checks that are going to happen intrinsically as part of the array access.

E.g.:

if (i < 0 || i >= myArray.size) {
    throw IonException("Invalid something...")
}
val x = myArray[i]

vs.

val x = try {
    myArray[i]
} catch (e: ArrayIndexOutOfBoundsException) {
    throw IonException("Invalid something...")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions