當前位置: 首頁>>代碼示例>>Java>>正文


Java TimeUtil類代碼示例

本文整理匯總了Java中org.apache.tinkerpop.gremlin.util.TimeUtil的典型用法代碼示例。如果您正苦於以下問題:Java TimeUtil類的具體用法?Java TimeUtil怎麽用?Java TimeUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TimeUtil類屬於org.apache.tinkerpop.gremlin.util包,在下文中一共展示了TimeUtil類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPlay6

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
@Ignore
public void testPlay6() throws Exception {
    final Graph graph = TinkerGraph.open();
    final GraphTraversalSource g = graph.traversal();
    for (int i = 0; i < 1000; i++) {
        graph.addVertex(T.label, "person", T.id, i);
    }
    graph.vertices().forEachRemaining(a -> {
        graph.vertices().forEachRemaining(b -> {
            if (a != b) {
                a.addEdge("knows", b);
            }
        });
    });
    graph.vertices(50).next().addEdge("uncle", graph.vertices(70).next());
    logger.info(TimeUtil.clockWithResult(500, () -> g.V().match(as("a").out("knows").as("b"), as("a").out("uncle").as("b")).toList()).toString());
}
 
開發者ID:ShiftLeftSecurity,項目名稱:tinkergraph-gremlin,代碼行數:19,代碼來源:TinkerGraphPlayTest.java

示例2: shouldProcessRequestsOutOfOrder

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
public void shouldProcessRequestsOutOfOrder() throws Exception {
    final Cluster cluster = Cluster.open();
    final Client client = cluster.connect();

    final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
    final ResultSet rsZero = client.submit("'zero'");

    final CompletableFuture<List<Result>> futureFive = rsFive.all();
    final CompletableFuture<List<Result>> futureZero = rsZero.all();

    final long start = System.nanoTime();
    assertFalse(futureFive.isDone());
    assertEquals("zero", futureZero.get().get(0).getString());

    logger.info("Eval of 'zero' complete: " + TimeUtil.millisSince(start));

    assertFalse(futureFive.isDone());
    assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());

    logger.info("Eval of 'five' complete: " + TimeUtil.millisSince(start));
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:23,代碼來源:GremlinDriverIntegrateTest.java

示例3: testPlay7

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
@Ignore
public void testPlay7() throws Exception {
    /*TinkerGraph graph = TinkerGraph.open();
    graph.createIndex("name",Vertex.class);
    graph.io(GraphMLIo.build()).readGraph("/Users/marko/software/tinkerpop/tinkerpop3/data/grateful-dead.xml");*/
    //System.out.println(g.V().properties().key().groupCount().next());
    TinkerGraph graph = TinkerFactory.createModern();
    GraphTraversalSource g = graph.traversal();
    final List<Supplier<GraphTraversal<?, ?>>> traversals = Arrays.asList(
            () -> g.V().out().as("v").match(
                    __.as("v").outE().count().as("outDegree"),
                    __.as("v").inE().count().as("inDegree")).select("v", "outDegree", "inDegree").by(valueMap()).by().by().local(union(select("v"), select("inDegree", "outDegree")).unfold().fold())
    );

    traversals.forEach(traversal -> {
        logger.info("pre-strategy:  {}", traversal.get());
        logger.info("post-strategy: {}", traversal.get().iterate());
        logger.info(TimeUtil.clockWithResult(50, () -> traversal.get().toList()).toString());
    });
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:22,代碼來源:TinkerGraphPlayTest.java

示例4: shouldProcessRequestsOutOfOrder

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
public void shouldProcessRequestsOutOfOrder() throws Exception {
    final Cluster cluster = TestClientFactory.open();
    final Client client = cluster.connect();

    final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
    final ResultSet rsZero = client.submit("'zero'");

    final CompletableFuture<List<Result>> futureFive = rsFive.all();
    final CompletableFuture<List<Result>> futureZero = rsZero.all();

    final long start = System.nanoTime();
    assertFalse(futureFive.isDone());
    assertEquals("zero", futureZero.get().get(0).getString());

    logger.info("Eval of 'zero' complete: " + TimeUtil.millisSince(start));

    assertFalse(futureFive.isDone());
    assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());

    logger.info("Eval of 'five' complete: " + TimeUtil.millisSince(start));
}
 
開發者ID:apache,項目名稱:tinkerpop,代碼行數:23,代碼來源:GremlinDriverIntegrateTest.java

示例5: benchmarkGroup

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
@Ignore
public void benchmarkGroup() throws Exception {
    Graph graph = TinkerGraph.open();
    GraphTraversalSource g = graph.traversal();
    graph.io(GraphMLIo.build()).readGraph("../data/grateful-dead.xml");
    /////////

    //g.V().group().by(T.label).by(values("name")).forEachRemaining(x -> logger.info(x.toString()));

    System.out.println("group: " + g.V().both("followedBy").both("followedBy").group().by("songType").by(count()).next());
    System.out.println("groupV3d0: " + g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().by(__.count(Scope.local)).next());

    //
    System.out.println("\n\nBig Values -- by(songType)");

    System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("songType").by(count()).next()));
    System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().by(__.count(Scope.local)).next()) + "\n");

    ///

    System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("songType").by(fold()).next()));
    System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().next()));

    ///
    System.out.println("\n\nBig Keys -- by(name)");

    System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("name").by(count()).next()));
    System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("name").by().by(__.count(Scope.local)).next()) + "\n");

    ///

    System.out.println("group: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").group().by("name").by(fold()).next()));
    System.out.println("groupV3d0: " + TimeUtil.clock(10, () -> g.V().both("followedBy").both("followedBy").groupV3d0().by("name").by().next()));

}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:37,代碼來源:TinkerGraphPlayTest.java

示例6: shouldHaveFasterRuntimeWithLabelKeyValueIndex

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
public void shouldHaveFasterRuntimeWithLabelKeyValueIndex() throws Exception {
    final Neo4jGraph neo4j = (Neo4jGraph) this.graph;
    int maxVertices = 10000;
    for (int i = 0; i < maxVertices; i++) {
        if (i % 2 == 0)
            this.graph.addVertex(T.label, "something", "myId", i);
        else
            this.graph.addVertex(T.label, "nothing", "myId", i);
    }
    this.graph.tx().commit();

    // traversal
    final Runnable traversal = () -> {
        final Traversal<Vertex, Vertex> t = g.V().hasLabel("something").has("myId", 2000);
        final Vertex vertex = t.tryNext().get();
        assertFalse(t.hasNext());
        assertEquals(1, IteratorUtils.count(vertex.properties("myId")));
        assertEquals("something", vertex.label());
    };

    // no index
    this.graph.tx().readWrite();
    assertFalse(this.getBaseGraph().hasSchemaIndex("something", "myId"));
    TimeUtil.clock(20, traversal);
    final double noIndexTime = TimeUtil.clock(20, traversal);
    // index time
    neo4j.cypher("CREATE INDEX ON :something(myId)").iterate();
    this.graph.tx().commit();
    this.graph.tx().readWrite();
    Thread.sleep(5000); // wait for indices to be built
    assertTrue(this.getBaseGraph().hasSchemaIndex("something", "myId"));
    TimeUtil.clock(20, traversal);
    final double indexTime = TimeUtil.clock(20, traversal);
    logger.info("Query time (no-index vs. index): {}", noIndexTime + " vs. {}", indexTime);
    assertTrue((noIndexTime / 10) > indexTime); // should be at least 10x faster
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:38,代碼來源:NativeNeo4jIndexCheck.java

示例7: shouldHaveFasterRuntimeWithLabelKeyValueIndexOnMultiProperties

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
public void shouldHaveFasterRuntimeWithLabelKeyValueIndexOnMultiProperties() throws Exception {
    final Neo4jGraph neo4j = (Neo4jGraph) this.graph;
    int maxVertices = 10000;
    for (int i = 0; i < maxVertices; i++) {
        if (i % 2 == 0)
            this.graph.addVertex(T.label, "something", "myId", i, "myId", i + maxVertices + 1);
        else
            this.graph.addVertex(T.label, "nothing", "myId", i, "myId", i + maxVertices + 1);
    }
    this.graph.tx().commit();

    // traversal
    final Runnable traversal = () -> {
        final Traversal<Vertex, Vertex> t = g.V().hasLabel("something").has("myId", 2000 + maxVertices + 1);
        final Vertex vertex = t.tryNext().get();
        assertFalse(t.hasNext());
        assertEquals(2, IteratorUtils.count(vertex.properties("myId")));
        assertEquals("something", vertex.label());
    };

    // no index
    this.graph.tx().readWrite();
    assertFalse(this.getBaseGraph().hasSchemaIndex("something", "myId"));
    TimeUtil.clock(20, traversal);
    final double noIndexTime = TimeUtil.clock(20, traversal);
    // index time
    neo4j.cypher("CREATE INDEX ON :something(myId)").iterate();
    neo4j.cypher("CREATE INDEX ON :vertexProperty(myId)").iterate();
    this.graph.tx().commit();
    this.graph.tx().readWrite();
    Thread.sleep(5000); // wait for indices to be built
    assertTrue(this.getBaseGraph().hasSchemaIndex("something", "myId"));
    TimeUtil.clock(20, traversal);
    final double indexTime = TimeUtil.clock(20, traversal);
    logger.info("Query time (no-index vs. index): {}", noIndexTime + " vs. {}", indexTime);
    assertTrue((noIndexTime / 10) > indexTime); // should be at least 10x faster
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:41,代碼來源:NativeNeo4jIndexCheck.java

示例8: waitForConnection

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
private Connection waitForConnection(final long timeout, final TimeUnit unit) throws TimeoutException, ConnectionException {
    long start = System.nanoTime();
    long remaining = timeout;
    long to = timeout;
    do {
        try {
            awaitAvailableConnection(remaining, unit);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            to = 0;
        }

        if (isClosed())
            throw new ConnectionException(host.getHostUri(), host.getAddress(), "Pool is shutdown");

        final Connection leastUsed = selectLeastUsed();
        if (leastUsed != null) {
            while (true) {
                final int inFlight = leastUsed.borrowed.get();
                final int availableInProcess = leastUsed.availableInProcess();
                if (inFlight >= availableInProcess) {
                    logger.debug("Least used {} on {} has requests borrowed [{}] >= availableInProcess [{}] - may timeout waiting for connection",
                            leastUsed, host, inFlight, availableInProcess);
                    break;
                }

                if (leastUsed.borrowed.compareAndSet(inFlight, inFlight + 1)) {
                    if (logger.isDebugEnabled())
                        logger.debug("Return least used {} on {} after waiting", leastUsed.getConnectionInfo(), host);
                    return leastUsed;
                }
            }
        }

        remaining = to - TimeUtil.timeSince(start, unit);
        logger.debug("Continue to wait for connection on {} if {} > 0", host, remaining);
    } while (remaining > 0);

    logger.debug("Timed-out waiting for connection on {} - possibly unavailable", host);

    // if we timeout borrowing a connection that might mean the host is dead (or the timeout was super short).
    // either way supply a function to reconnect
    this.considerUnavailable();

    throw new TimeoutException();
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:47,代碼來源:ConnectionPool.java

示例9: shouldBeFaster

import org.apache.tinkerpop.gremlin.util.TimeUtil; //導入依賴的package包/類
@Test
public void shouldBeFaster() throws Exception {

    final TraversalStrategies withStrategyUnderTest = new DefaultTraversalStrategies();
    withStrategyUnderTest.addStrategies(getStrategyUnderTestInstance());

    final TraversalStrategies withoutStrategyUnderTest = new DefaultTraversalStrategies();
    withoutStrategyUnderTest.removeStrategies(getStrategyUnderTest());

    final int clockRuns = getClockRuns();
    final Iterator<GraphTraversal> iterator = getTraversalIterator();
    int faster = 0, numTraversals = 0;
    while (iterator.hasNext()) {

        final GraphTraversal traversal = iterator.next();
        final GraphTraversal.Admin original = traversal.asAdmin();
        final GraphTraversal.Admin optimized = original.clone();

        original.setStrategies(withoutStrategyUnderTest);
        optimized.setStrategies(withStrategyUnderTest);

        final double originalTime, optimizedTime;

        if (RANDOM.nextBoolean()) {
            originalTime = TimeUtil.clock(clockRuns, () -> original.clone().iterate());
            optimizedTime = TimeUtil.clock(clockRuns, () -> optimized.clone().iterate());
        } else {
            optimizedTime = TimeUtil.clock(clockRuns, () -> optimized.clone().iterate());
            originalTime = TimeUtil.clock(clockRuns, () -> original.clone().iterate());
        }

        final List originalResult = original.toList();
        final List optimizedResult = optimized.toList();

        if (originalTime > optimizedTime) {
            LOGGER.debug("Original traversal ({} ms): {}", originalTime, original);
            LOGGER.debug("Optimized traversal ({} ms): {}", optimizedTime, optimized);
        } else {
            LOGGER.warn("Original traversal ({} ms): {}", originalTime, original);
            LOGGER.warn("Optimized traversal ({} ms): {}", optimizedTime, optimized);
        }

        if (getAssertionPercentile() >= 100) assertTrue(originalTime > optimizedTime);
        else {
            if (originalTime > optimizedTime)
                faster++;
            numTraversals++;
        }

        assertEquals(originalResult, optimizedResult);
    }

    if (getAssertionPercentile() < 100 && numTraversals > 0)
        assertTrue(((faster * 100.0) / numTraversals) >= getAssertionPercentile());
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:56,代碼來源:TraversalStrategyPerformanceTest.java


注:本文中的org.apache.tinkerpop.gremlin.util.TimeUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。