-
Notifications
You must be signed in to change notification settings - Fork 251
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
Refactor code of WithFirstSpliterator #232
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2015, 2020 StreamEx contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package one.util.streamex.benchmark.withFirst; | ||
|
||
import one.util.streamex.IntStreamEx; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
@State(Scope.Benchmark) | ||
public class WithFirstBenchmark { | ||
@Param({"100000"}) | ||
private int N; | ||
|
||
@Benchmark | ||
public Object[] parallelOld() { | ||
return IntStreamEx.range(N).boxed().parallel().withFirstOld().toArray(); | ||
} | ||
|
||
@Benchmark | ||
public boolean parallelOldShortCircuit() { | ||
return IntStreamEx.range(N).boxed().parallel().withFirstOld().anyMatch(x -> x.getKey() == -1); | ||
} | ||
|
||
@Benchmark | ||
public Object[] parallelNew() { | ||
return IntStreamEx.range(N).boxed().parallel().withFirst().toArray(); | ||
} | ||
|
||
@Benchmark | ||
public boolean parallelNewShortCircuit() { | ||
return IntStreamEx.range(N).boxed().parallel().withFirst().anyMatch(x -> x.getKey() == -1); | ||
} | ||
|
||
@Benchmark | ||
public Object[] sequentialOld() { | ||
return IntStreamEx.range(N).boxed().withFirstOld().toArray(); | ||
} | ||
|
||
@Benchmark | ||
public boolean sequentialOldShortCircuit() { | ||
return IntStreamEx.range(N).boxed().withFirstOld().anyMatch(x -> x.getKey() == -1); | ||
} | ||
|
||
@Benchmark | ||
public Object[] sequentialNew() { | ||
return IntStreamEx.range(N).boxed().withFirst().toArray(); | ||
} | ||
|
||
@Benchmark | ||
public boolean sequentialNewShortCircuit() { | ||
return IntStreamEx.range(N).boxed().withFirst().anyMatch(x -> x.getKey() == -1); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(WithFirstBenchmark.class.getSimpleName()) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
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, indeed this should be changed. I forgot to update this part in version 0.6.4 when semantics of withFirst changed. However, it's better to say that the size remains the same than removing this completely. I will apply this change separately.