1 6 7 package com.hp.hpl.jena.mem.test; 8 9 12 13 import com.hp.hpl.jena.graph.*; 14 import com.hp.hpl.jena.graph.test.*; 15 import com.hp.hpl.jena.mem.GraphMem; 16 import com.hp.hpl.jena.util.iterator.*; 17 18 public class TestStoreSpeed extends GraphTestBase 19 { 20 private long began; 21 22 public TestStoreSpeed( String name ) 23 { 24 super( name ); 25 } 26 27 public static void main( String [] args ) 28 { 29 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "subject StoreMem", new GraphMem() ); 30 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "normal StoreMem", new GraphMem() ); 31 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "GraphMem", new GraphMem() ); 32 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "subject StoreMem", new GraphMem() ); 33 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "normal StoreMem", new GraphMem() ); 34 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "GraphMem", new GraphMem() ); 35 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "subject StoreMem", new GraphMem() ); 36 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "normal StoreMem", new GraphMem() ); 37 new TestStoreSpeed( "vladimir taltos" ) .gonzales( "GraphMem", new GraphMem() ); 38 } 39 40 private void mark() 41 { 42 began = System.currentTimeMillis(); 43 } 44 45 static final int COUNT = 100000; 46 47 private Triple newt( int i ) 48 { return new Triple( node("s" + (i % 1000)), node("p" + ((i + 11) % 20)), node("s" + ((i + 131) % 1001) ) ); } 49 50 private void makeTriples() 51 { for (int i = 0; i < COUNT; i += 1) newt( i ); } 52 53 private void fillGraph( Graph g ) 54 { 55 for (int i = 0; i < COUNT; i += 1) g.add( newt( i ) ); 56 } 57 58 private long ticktock( String title ) 59 { 60 long ticks = System.currentTimeMillis() - began; 61 System.err.println( "+ " + title + " took: " + ticks + "ms." ); 62 mark(); 63 return ticks; 64 } 65 66 private void consumeAll( Graph g ) 67 { 68 int count = 0; 69 ClosableIterator it = g.find( node("s500"), null, null ); 70 while (it.hasNext()) { it.next(); count += 1; } 71 } 74 75 private void gonzales( String title, Graph g ) 76 { 77 System.err.println( "" ); 78 System.err.println( "| gonzales: " + title ); 79 mark(); 80 makeTriples(); ticktock( "generating triples" ); 81 makeTriples(); ticktock( "generating triples again" ); 82 makeTriples(); long gen = ticktock( "generating triples yet again" ); 83 fillGraph( g ); long fill = ticktock( "filling graph" ); 84 System.err.println( "> insertion time: " + (fill - gen) ); 85 fillGraph( g ); ticktock( "adding the same triples again" ); 86 consumeAll( g ); ticktock( "counting s500 triples" ); 87 consumeAll( g ); ticktock( "counting s500 triples again" ); 88 consumeAll( g ); ticktock( "counting s500 triples yet again" ); 89 } 90 } 91 92 121 | Popular Tags |