Search in sources :

Example 46 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project elephant-bird by twitter.

the class TimeProtoConversions method main.

/**
 * @param args
 * @throws ExecException
 */
public static void main(String[] args) throws ExecException {
    int iterations = 100000;
    ProtobufToPig protoConv = new ProtobufToPig();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
        t = new ProtobufTuple(proto);
        t.get(0);
    }
    StopWatch timer = new StopWatch();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = protoConv.toTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
    timer.reset();
    timer.start();
    for (int i = 0; i < iterations; i++) {
        Person proto = Fixtures.buildPersonProto();
        Tuple t = new ProtobufTuple(proto);
        t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
}
Also used : ProtobufToPig(com.twitter.elephantbird.pig.util.ProtobufToPig) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Person(com.twitter.data.proto.tutorial.AddressBookProtos.Person) ProtobufTuple(com.twitter.elephantbird.pig.util.ProtobufTuple) Tuple(org.apache.pig.data.Tuple) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 47 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project simplejpa by appoxy.

the class PerformanceTests method testPutQueryDelete.

@Test
public void testPutQueryDelete() throws ExecutionException, InterruptedException {
    int numItems = 1;
    String x;
    EntityManagerSimpleJPA em = (EntityManagerSimpleJPA) factory.createEntityManager();
    PerformanceTestObject o = new PerformanceTestObject();
    o.setS1("first to create domain");
    em.persist(o);
    StopWatch stopWatch = new StopWatch();
    String s1a = "attribute1";
    String s2a = "attribute2";
    Future<PerformanceTestObject> lastFuture = null;
    stopWatch.start();
    for (int i = 0; i < numItems; i++) {
        o = new PerformanceTestObject();
        o.setS1(s1a);
        o.setS2(s2a);
        lastFuture = em.persistAsync(o);
    }
    // not 100% accurate, but good enough
    lastFuture.get();
    stopWatch.stop();
    System.out.println("puts duration=" + stopWatch.getTime() + ", " + em.getTotalOpStats().getPuts() + " items put.");
    Thread.sleep(5000);
    stopWatch.reset();
    stopWatch.start();
    Query query = em.createQuery("select o from PerformanceTestObject o");
    List<PerformanceTestObject> resultList = query.getResultList();
    System.out.println("iterating result list...");
    int i = 0;
    for (PerformanceTestObject performanceTestObject : resultList) {
        i++;
        if (i % 100 == 0) {
            System.out.println(i);
        }
    }
    stopWatch.stop();
    System.out.println("query ALL duration=" + stopWatch.getTime() + ", " + em.getTotalOpStats().getGets() + " items got.");
    stopWatch.reset();
    stopWatch.start();
    System.out.println("Deleting ALL...");
    for (PerformanceTestObject performanceTestObject : resultList) {
        lastFuture = em.removeAsync(o);
    }
    lastFuture.get();
    stopWatch.stop();
    System.out.println("delete duration=" + stopWatch.getTime() + ", " + resultList.size() + " items deleted.");
    System.out.println("sleeping...");
    Thread.sleep(30000);
    em.close();
}
Also used : Query(javax.persistence.Query) StopWatch(org.apache.commons.lang.time.StopWatch) Test(org.junit.Test)

Example 48 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project fastjson by alibaba.

the class TestFastJson method testDeserializePerformance.

public void testDeserializePerformance() throws IOException, ClassNotFoundException {
    Object obj = createTest();
    byte[] bytes = JSON.toJSONBytes(obj, SerializerFeature.WriteClassName);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(obj);
    byte[] javaBytes = os.toByteArray();
    System.out.println(bytes.length);
    for (int x = 0; x < 20; ++x) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            // ByteArrayInputStream is = new ByteArrayInputStream(bytes);
            Object o = jsonDeserialize(bytes, GenericRS.class);
            o.getClass();
        }
        stopWatch.stop();
        System.out.println("JSON deserialize:" + stopWatch.getTime());
        stopWatch.reset();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            Object o = javaDeserialize(javaBytes);
            o.getClass();
        }
        stopWatch.stop();
        System.out.println("JAVA deserialize:" + stopWatch.getTime());
        System.out.println();
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 49 with StopWatch

use of org.apache.commons.lang.time.StopWatch in project fastjson by alibaba.

the class TestFastJson method testFP.

public void testFP() throws IOException {
    Generic<String> q = new Generic<String>();
    for (int x = 0; x < STAYS_COUNT; ++x) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            jsonSerialize(q);
        }
        stopWatch.stop();
        System.out.println("JSON serialize:" + stopWatch.getTime());
        stopWatch.reset();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            javaSerialize(q);
        }
        stopWatch.stop();
        System.out.println("JAVA serialize:" + stopWatch.getTime());
        System.out.println();
    }
}
Also used : StopWatch(org.apache.commons.lang.time.StopWatch)

Aggregations

StopWatch (org.apache.commons.lang.time.StopWatch)49 IOException (java.io.IOException)13 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 File (java.io.File)4 Path (java.nio.file.Path)4 HashMap (java.util.HashMap)4 FileNotFoundException (java.io.FileNotFoundException)3 ObjectOutputStream (java.io.ObjectOutputStream)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Map (java.util.Map)3 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)3 YarnApplicationReport (com.continuuity.weave.internal.yarn.YarnApplicationReport)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 HashSet (java.util.HashSet)2