Package com.tinkerpop.blueprints.impls.neo4j

Source Code of com.tinkerpop.blueprints.impls.neo4j.Neo4jBenchmarkTestSuite

package com.tinkerpop.blueprints.impls.neo4j;

import com.tinkerpop.blueprints.BaseTest;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.TestSuite;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.GraphTest;
import com.tinkerpop.blueprints.util.io.graphml.GraphMLReader;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class Neo4jBenchmarkTestSuite extends TestSuite {

    private static final int TOTAL_RUNS = 10;

    public Neo4jBenchmarkTestSuite() {
    }

    public Neo4jBenchmarkTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testNeo4jRaw() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            GraphDatabaseService neo4j = ((Neo4jGraph) graph).getRawGraph();
            int counter = 0;
            this.stopWatch();
            for (final Node node : neo4j.getAllNodes()) {
                counter++;
                for (final Relationship relationship : node.getRelationships(Direction.OUTGOING)) {
                    counter++;
                    final Node node2 = relationship.getEndNode();
                    counter++;
                    for (final Relationship relationship2 : node2.getRelationships(Direction.OUTGOING)) {
                        counter++;
                        final Node node3 = relationship2.getEndNode();
                        counter++;
                        for (final Relationship relationship3 : node3.getRelationships(Direction.OUTGOING)) {
                            counter++;
                            relationship3.getEndNode();
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(neo4j.toString(), counter, "Neo4j raw elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jRaw", 1, "Neo4j Raw experiment average", totalTime / (double) TOTAL_RUNS);
    }

    public void testNeo4jGraph() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            this.stopWatch();
            int counter = 0;
            for (final Vertex vertex : graph.getVertices()) {
                counter++;
                for (final Edge edge : vertex.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                    counter++;
                    final Vertex vertex2 = edge.getVertex(com.tinkerpop.blueprints.Direction.IN);
                    counter++;
                    for (final Edge edge2 : vertex2.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                        counter++;
                        final Vertex vertex3 = edge2.getVertex(com.tinkerpop.blueprints.Direction.IN);
                        counter++;
                        for (final Edge edge3 : vertex3.getEdges(com.tinkerpop.blueprints.Direction.OUT)) {
                            counter++;
                            edge3.getVertex(com.tinkerpop.blueprints.Direction.OUT);
                            counter++;
                        }
                    }
                }
            }
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(graph.toString(), counter, "Neo4jGraph elements touched", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("Neo4jGraph", 1, "Neo4jGraph experiment average", totalTime / (double) TOTAL_RUNS);
    }


}
TOP

Related Classes of com.tinkerpop.blueprints.impls.neo4j.Neo4jBenchmarkTestSuite

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.