Skip to content

Commit

Permalink
add graphql-java benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Jul 8, 2023
1 parent a9b796b commit 3f97d78
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version
junit = { group = "junit", name = "junit", version.ref = "junit" }
kotlin-allopen = { group = "org.jetbrains.kotlin", name = "kotlin-allopen", version.ref = "kotlin-plugin" }
kotlin-compiletesting = { group = "com.github.tschuchortdev", name = "kotlin-compile-testing", version = "1.5.0" }
graphql-java = "com.graphql-java:graphql-java:20.4"
# The main kotlin version for build-logic and Gradle tests
kotlin-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin-plugin" }
# For Gradle integration tests to make sure we stay compatible with 1.5.0
Expand Down
2 changes: 2 additions & 0 deletions tests/ast-benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ benchmark {

dependencies {
implementation("com.apollographql.apollo3:apollo-ast")
implementation(golatac.lib("graphql.java"))
implementation("org.jetbrains.kotlin:kotlin-test")

add("jmhImplementation", golatac.lib("kotlinx.benchmark.runtime"))
add("jmhImplementation", sourceSets.main.get().output + sourceSets.main.get().runtimeClasspath)
Expand Down
14 changes: 14 additions & 0 deletions tests/ast-benchmark/src/jmh/kotlin/benchmark/Benchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ open class Benchmark {
testFiles = File(".").resolve("../../libraries/apollo-compiler/src/test/graphql")
.walk()
.filter { it.extension in setOf("graphql", "graphqls") }
.filter {
when (it.parentFile.name) {
"empty", "__schema" -> false // contains empty document which are not spec compliant
"simple_fragment" -> false // contains operation/fragment descriptions which are not spec compliant
else -> true
}
}
.toList()
}

Expand All @@ -42,4 +49,11 @@ open class Benchmark {
it.source().buffer().parseAsGQLDocument(options = ParserOptions(useAntlr = false)).getOrThrow().definitions.size.toDouble()
}
}

@Benchmark
fun graphqlJava(): Double {
return testFiles.sumOf {
graphql.parser.Parser.parse(it.readText()).definitions.size.toDouble()
}
}
}

0 comments on commit 3f97d78

Please sign in to comment.