Last active
April 4, 2017 14:35
-
-
Save robertdale/8b4e604165852a5344476af940b75e30 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
// cut and paste or run with ./bin/gremlin.sh -i mustafa.groovy | |
graph = TinkerGraph.open() | |
System.out.println("graph open"); | |
g = graph.traversal(); | |
System.out.println("vertex creation started"); | |
n = 10000; | |
for (i = 0; i < n; i++) { | |
System.out.print('.'); | |
graph.addVertex("NodeId", i); | |
} | |
k = (n / 2); | |
System.out.println("edge creation started"); | |
for (j = 0; j < k; j++) { | |
v = g.V().has("NodeId", j).next(); | |
System.out.print('.'); | |
c1 = g.V().has("NodeId", (j * 2 + 1)).next() | |
if (c1) { | |
v.addEdge("childs", c1); | |
} | |
c2 = g.V().has("NodeId", (j * 2 + 1)).next() | |
if (c2) { | |
v.addEdge("childs", c2); | |
} | |
} | |
System.out.println("Graph is created....."); | |
System.out.println("graph is " + graph); | |
fromNode = g.V().has("NodeId", 0).next(); | |
System.out.println("Node for calculating its child nodes : " + fromNode.property("NodeId")); | |
st = System.currentTimeMillis(); | |
System.out.println(g.V(fromNode).repeat(out("childs").dedup()).emit().count().next()); | |
//System.out.println(g.V(fromNode).repeat(out("childs")).emit().until(out("childs").count().is(0)).count().next()); | |
System.out.println("time : " + (System.currentTimeMillis() - st) + " milliseconds"); | |
System.out.println("code to retrieve only children node"); | |
st = System.currentTimeMillis(); | |
fromNode = g.V().has("NodeId", 0).next(); | |
System.out.println("Node for calculating its child nodes : " + fromNode.property("NodeId")); | |
System.out.println(g.V(fromNode).repeat(out("childs").dedup()).emit().count().next()); | |
System.out.println("time : " + (System.currentTimeMillis() - st) + " milliseconds"); | |
// these won't print results from the script thus will have to be pasted into the console separately | |
clockWithResult{ g.V(fromNode).repeat(__.out("childs").dedup()).times(13).emit().count().next()} | |
// these won't print results from the script thus will have to be pasted into the console separately | |
clockWithResult{ g.V(fromNode).repeat(out("childs")).times(12).emit().count().next()} | |
// these won't print results from the script thus will have to be pasted into the console separately | |
g.V(fromNode).repeat(out("childs")).times(12).emit().count().profile() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment