Skip to content

Instantly share code, notes, and snippets.

@bbakerman
Created September 4, 2020 07:32
Show Gist options
  • Save bbakerman/920c8bfa01ea309fd598b41f370626b8 to your computer and use it in GitHub Desktop.
Save bbakerman/920c8bfa01ea309fd598b41f370626b8 to your computer and use it in GitHub Desktop.
static class Stopwatch {
long then = System.currentTimeMillis()
void say(String message) {
long ms = System.currentTimeMillis()-then
System.out.printf("+%dms %s\n", ms, message)
}
void start(String message) {
then = System.currentTimeMillis()
say(message)
}
}
static class DataNode {
String data
List<DataNode> nodes
DataNode(Integer depth, Integer width) {
this.data = "${depth}x${width}"
this.nodes = mkNodes(depth, width)
}
String getData() {
return data
}
List<DataNode> getNodes() {
return nodes
}
static List<DataNode> mkNodes(Integer depth, Integer width) {
def nodes = []
if (depth > 0) {
for (Integer i = 0; i < width; i++) {
nodes.add(new DataNode(depth - 1, width))
}
}
return nodes
}
@Override
String toString() {
return data
}
}
def "big data"() {
def sdl = """
type Query {
nodeQuery : NodeQuery
}
type NodeQuery {
nodes : [Node]
}
type Node {
data : String
nodes : [Node]
}
"""
DataFetcher nodeQueryDF = { DataFetchingEnvironment env ->
return env.getRoot()
}
def graphQL = TestUtil.graphQL(sdl, ["Query": ["nodeQuery": nodeQueryDF]]).build()
when:
def stopwatch = new Stopwatch()
stopwatch.say("Building data...")
def rootNode = new DataNode(3, 100)
def query = """ query {
nodeQuery {
nodes {
data
nodes {
data
nodes {
data
}
}
}
}
}
"""
def ei = newExecutionInput().root(rootNode).query(query).build()
// warm up
stopwatch.start("Running query warmup...")
graphQL.execute(ei)
stopwatch.say("Finished query warmup...")
stopwatch.start("Starting query...")
def er = graphQL.execute(ei)
then:
stopwatch.say("done")
er.data != null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment