Created
September 21, 2018 12:08
-
-
Save minborg/fc8f87737371918608a1e1ba349937fb 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
package com.example; | |
import com.company.sakila.SakilaApplicationBuilder; | |
import com.company.sakila.sakila.sakila.film.Film; | |
import com.company.sakila.sakila.sakila.film.FilmManager; | |
import com.company.sakila.sakila.sakila.film.generated.GeneratedFilm; | |
import com.speedment.enterprise.application.InMemoryBundle; | |
import com.speedment.enterprise.datastore.runtime.DataStoreComponent; | |
import com.speedment.runtime.core.Speedment; | |
import com.speedment.runtime.core.manager.Manager; | |
import org.openjdk.jmh.annotations.*; | |
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; | |
import java.util.Comparator; | |
import java.util.IntSummaryStatistics; | |
import java.util.Random; | |
import java.util.function.Consumer; | |
import java.util.function.Predicate; | |
import static java.util.stream.Collectors.joining; | |
@State(Scope.Benchmark) | |
public class GraalBench { | |
private static final Predicate<Film> RATING_EQUALS_PG_13 = Film.RATING.equal(GeneratedFilm.Rating.PG13); | |
private static final Comparator<Film> LENGTH_DESCENDING = Film.LENGTH.reversed(); | |
private Speedment app; | |
private Manager<Film> films; | |
@Setup(/*Level.Iteration*/) | |
public void setup() { | |
System.out.println(System.getProperty("java.vm.name")); | |
app = new SakilaApplicationBuilder() | |
.withPassword("sakila-password") | |
.withBundle(InMemoryBundle.class) | |
.build(); | |
app.get(DataStoreComponent.class).ifPresent(DataStoreComponent::load); | |
films = app.getOrThrow(FilmManager.class); | |
} | |
@TearDown(/*Level.Iteration*/) | |
public void tearDown() { | |
app.close(); | |
} | |
@Benchmark | |
public long filterAndCount() { | |
return films.stream() | |
.filter(RATING_EQUALS_PG_13) | |
.count(); | |
} | |
@Benchmark | |
public IntSummaryStatistics complex() { | |
return films.stream() | |
.sorted(LENGTH_DESCENDING) | |
.skip(745) | |
.limit(5) | |
.mapToInt(Film.RENTAL_DURATION.asInt()) | |
.summaryStatistics(); | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder() | |
.include(GraalBench.class.getSimpleName()) | |
.mode(Mode.Throughput) | |
.threads(Threads.MAX) | |
.forks(1) | |
.warmupIterations(5) | |
.measurementIterations(5) | |
.build(); | |
new Runner(opt).run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment