-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2911 from graphql-java/benchmark_enf
Reduce calculation for fragments in ExecutableNormalizedOperation
- Loading branch information
Showing
6 changed files
with
18,278 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package benchmark; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.io.Resources; | ||
import graphql.execution.CoercedVariables; | ||
import graphql.language.Document; | ||
import graphql.normalized.ExecutableNormalizedOperation; | ||
import graphql.normalized.ExecutableNormalizedOperationFactory; | ||
import graphql.parser.Parser; | ||
import graphql.schema.GraphQLSchema; | ||
import graphql.schema.idl.SchemaGenerator; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.google.common.io.Resources.getResource; | ||
|
||
@State(Scope.Benchmark) | ||
@BenchmarkMode(Mode.Throughput) | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 2, timeUnit = TimeUnit.NANOSECONDS) | ||
public class NQExtraLargeBenchmark { | ||
|
||
@State(Scope.Benchmark) | ||
public static class MyState { | ||
|
||
GraphQLSchema schema; | ||
Document document; | ||
|
||
@Setup | ||
public void setup() { | ||
try { | ||
String schemaString = readFromClasspath("extra-large-schema-1.graphqls"); | ||
schema = SchemaGenerator.createdMockedSchema(schemaString); | ||
|
||
String query = readFromClasspath("extra-large-schema-1-query.graphql"); | ||
document = Parser.parse(query); | ||
} catch (Exception e) { | ||
System.out.println(e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private String readFromClasspath(String file) throws IOException { | ||
URL url = getResource(file); | ||
return Resources.toString(url, Charsets.UTF_8); | ||
} | ||
} | ||
|
||
@Benchmark | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 3, time = 10) | ||
@Threads(1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
public void benchMarkAvgTime(MyState myState, Blackhole blackhole ) { | ||
runImpl(myState, blackhole); | ||
} | ||
|
||
@Benchmark | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 3, time = 10) | ||
@Threads(1) | ||
@Fork(3) | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void benchMarkThroughput(MyState myState, Blackhole blackhole ) { | ||
runImpl(myState, blackhole); | ||
} | ||
|
||
private void runImpl(MyState myState, Blackhole blackhole) { | ||
ExecutableNormalizedOperation executableNormalizedOperation = ExecutableNormalizedOperationFactory.createExecutableNormalizedOperation(myState.schema, myState.document, null, CoercedVariables.emptyVariables()); | ||
blackhole.consume(executableNormalizedOperation); | ||
} | ||
} |
Oops, something went wrong.