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
Added benchmarks for common java idioms #1456
Conversation
@danieldietrich this is just preliminary to see if the general outline of the test looks good. |
|
||
@Benchmark | ||
public Object javaslang_for() { | ||
Integer result = For(ELEMENTS_ARRAY).yield(i -> i).reduce((i, j) -> i + j); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing alternative benchmarks :).
It would be nice if the build would be passing before asking for code reviews.
Also, please use the same style as the other benchmarks do (e.g. final local variables, method naming, encapsulation in separate classes with a base class)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update, didnt notice it was triggering CI.
Tests are failing because of OOM, since For comprehension essentially does a cross product I'll use smaller arrays. |
for (Integer i : ELEMENTS_ARRAY) { | ||
for (Integer j : ELEMENTS_ARRAY) { | ||
for (Integer k : ELEMENTS_ARRAY) { | ||
result.add(i * j * k * 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 0
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just needed something to ensure the assert is simple.
ELEMENTS_ARRAY = Arrays.asList(ELEMENTS); | ||
} | ||
|
||
protected Object consume(Blackhole bh, Integer i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blackhole
is from JMH and is designed for the case where you don't need/want to check the result but you do want to prevent DCE, so it's basically something to emulate a side-effect function.
Tests should be simpler now, here's what I have (cannot explain the 2nd result)
|
Will check it out next week (I'm very busy, sorry), until then, please simplify everything as much as possible. |
Current coverage is 96.84% (diff: 100%)@@ master #1456 diff @@
==========================================
Files 88 88
Lines 10675 10675
Methods 0 0
Messages 0 0
Branches 1818 1818
==========================================
Hits 10338 10338
Misses 194 194
Partials 143 143
|
Will use a xor, thanks. |
public int CONTAINER_SIZE; | ||
|
||
Integer[] ELEMENTS; | ||
List<Integer> ELEMENTS_ARRAY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem like an array :)
Do you need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I just need a list.
Geez, I'm getting horrible results with the XOR trick. @paplorinc can you share you idea with some code? I'm currently doing this:
But the results are horrible in comparison to the nested |
I would be surprised if the simple for loop (which is often optimized by JIT anyway) wouldn't be at least |
Cool, I will proceed then, and add more benchmarks, for the rest of the idioms. |
Try it out and report your findings :) |
Added a couple more benchmarks, now only pattern matching is missing.
|
|
||
``` | ||
mvn clean test -Pbenchmark | ||
mvn clean test -pl javaslang-benchmark -Dtest=TryBenchmark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we already run a specific microbenchmark here? See line 37 and line 40.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, too much copy/paste. Will fix.
No I don't. Will check it out today. Was an assert that failed :( |
A blog post would be awesome! I would appreciate to review it before publishing because interpreting benchmarks is a difficult topic. @paplorinc and others may also be interested to take a look! Actually I don't know how to run the benchmarks :-/ The recent command |
Sure, a blog post would be nice, but a lot of things are very hard to interpret here currently, I really urge you to understand JMH well first, it's a lot more difficult than it seems - and as I tried to point out in these benchmarks, they are still far from being finished. |
d0ac73b
to
8745c74
Compare
I appreciate everyone's advice and input, I realize it's very tricky to interpret the results but my goal was never to provide an accurate measurement. I just want to get an idea of what to expect in terms of performance. I know using JMH is hard, but I think this is a good and practical way to learn |
@mping Yes, we need that blog post. I would greatly appreciate if you would write a guest post on the Javaslang blog, including your Bio (/Photo etc) :-) The format is would be markdown. |
|
||
@State(Scope.Benchmark) | ||
public static class Base { | ||
@Param({ "10" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide more params so that we can observe a trend
- For comprehension - Tuple - Try - Pattern Matching
8745c74
to
cd1b8e0
Compare
I will pull this PR in now - we need to burn down our issues and PRs in order to get forward. Optimizations of the Benchmarks can occur later. @mping Many thanks!! |
@danieldietrich yay thanks! |
JFYI, looks like the error was mentioned by danieldietrich on 24 Aug 2016 is still here: Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.475 sec <<< FAILURE! - in io.vavr.idiom.ForBenchmark |
@AnthonyKot thank you, I will create an issue |
Hopefully will have the following benchmarks: