Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add helpers to wrap lambdas with a timer #1087

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

brharrington
Copy link
Contributor

Adds helpers to the Timer interface to wrap the common lambda types in java.util.function. This can be useful to wrap a lambda that is passed to another class in order to measure each invocation. For example:

Timer t = registry.timer(id);
int sum = Arrays
    .stream(new String[] {"foo", "bar", "baz"})
    .mapToInt(t.wrapToIntFunction(String::length))
    .sum();

Caller should ensure that the lambda does sufficient work that timing an invocatino will not be more costly than executing the lambda body.

Adds helpers to the Timer interface to wrap the common
lambda types in `java.util.function`. This can be useful
to wrap a lambda that is passed to another class in order
to measure each invocation. For example:

```java
Timer t = registry.timer(id);
int sum = Arrays
    .stream(new String[] {"foo", "bar", "baz"})
    .mapToInt(t.wrapToIntFunction(String::length))
    .sum();
```

Caller should ensure that the lambda does sufficient
work that timing an invocatino will not be more costly
than executing the lambda body.
@brharrington brharrington added this to the 1.7.0 milestone Oct 25, 2023
@brharrington brharrington merged commit 5e44940 into Netflix:main Oct 25, 2023
1 check passed
@brharrington brharrington deleted the wrap branch October 25, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant