Created
January 26, 2016 18:05
-
-
Save apangin/fc458d81829931374f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark (generator) (length) (postprocess) Mode Cnt Score Error Units | |
ListIndexOf.indexOf random 1000000 none avgt 10 1,243 ± 0,031 ms/op | |
ListIndexOf.indexOf random 1000000 sort avgt 10 6,496 ± 0,456 ms/op | |
ListIndexOf.indexOf random 1000000 shuffle avgt 10 6,485 ± 0,412 ms/op | |
ListIndexOf.indexOf sequential 1000000 none avgt 10 1,249 ± 0,053 ms/op | |
ListIndexOf.indexOf sequential 1000000 sort avgt 10 1,247 ± 0,037 ms/op | |
ListIndexOf.indexOf sequential 1000000 shuffle avgt 10 6,579 ± 0,448 ms/op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bench; | |
import org.openjdk.jmh.annotations.*; | |
import java.util.*; | |
import java.util.stream.Collectors; | |
import java.util.stream.IntStream; | |
@State(Scope.Benchmark) | |
public class ListIndexOf { | |
private static final Random random = new Random(0); | |
@Param("1000000") | |
private int length; | |
@Param({"random", "sequential"}) | |
private String generator; | |
@Param({"none", "sort", "shuffle"}) | |
private String postprocess; | |
private List<Double> list; | |
@Setup | |
public void setup() { | |
if ("random".equals(generator)) { | |
list = random.doubles(length).boxed().collect(Collectors.toList()); | |
} else if ("sequential".equals(generator)) { | |
list = IntStream.range(0, length).asDoubleStream().boxed().collect(Collectors.toList()); | |
} | |
if ("sort".equals(postprocess)) { | |
Collections.sort(list); | |
} else if ("shuffle".equals(postprocess)) { | |
Collections.shuffle(list); | |
} | |
} | |
@Benchmark | |
public int indexOf() { | |
int index = random.nextInt(length); | |
return list.indexOf(list.get(index)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment