KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > mem > test > TestStoreSpeed


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestStoreSpeed.java,v 1.2 2005/02/21 12:04:01 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.mem.test;
8
9 /**
10     @author kers
11 */

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 JavaDoc name )
23         {
24         super( name );
25         }
26
27     public static void main( String JavaDoc [] 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 JavaDoc 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; /* if (count %1000 == 0) System.err.print( (count / 1000) %10 ); */}
71         // System.err.println( "| we have " + count + " triples." );
72
// assertEquals( g.size(), count );
73
}
74         
75     private void gonzales( String JavaDoc 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 /*
93     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
94     All rights reserved.
95
96     Redistribution and use in source and binary forms, with or without
97     modification, are permitted provided that the following conditions
98     are met:
99
100     1. Redistributions of source code must retain the above copyright
101        notice, this list of conditions and the following disclaimer.
102
103     2. Redistributions in binary form must reproduce the above copyright
104        notice, this list of conditions and the following disclaimer in the
105        documentation and/or other materials provided with the distribution.
106
107     3. The name of the author may not be used to endorse or promote products
108        derived from this software without specific prior written permission.
109
110     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
111     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
112     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
113     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
114     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
115     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
116     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
117     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
118     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
119     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
120 */

121
Popular Tags