001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestStoreSpeed.java,v 1.6 2008/01/02 12:09:01 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.mem.test;
008:
009: /**
010: @author kers
011: */
012:
013: import com.hp.hpl.jena.graph.*;
014: import com.hp.hpl.jena.graph.test.*;
015: import com.hp.hpl.jena.util.iterator.*;
016:
017: public class TestStoreSpeed extends GraphTestBase {
018: private long began;
019:
020: public TestStoreSpeed(String name) {
021: super (name);
022: }
023:
024: public static void main(String[] args) {
025: new TestStoreSpeed("vladimir taltos").gonzales(
026: "subject StoreMem", Factory.createGraphMem());
027: new TestStoreSpeed("vladimir taltos").gonzales(
028: "normal StoreMem", Factory.createGraphMem());
029: new TestStoreSpeed("vladimir taltos").gonzales("GraphMem",
030: Factory.createGraphMem());
031: new TestStoreSpeed("vladimir taltos").gonzales(
032: "subject StoreMem", Factory.createGraphMem());
033: new TestStoreSpeed("vladimir taltos").gonzales(
034: "normal StoreMem", Factory.createGraphMem());
035: new TestStoreSpeed("vladimir taltos").gonzales("GraphMem",
036: Factory.createGraphMem());
037: new TestStoreSpeed("vladimir taltos").gonzales(
038: "subject StoreMem", Factory.createGraphMem());
039: new TestStoreSpeed("vladimir taltos").gonzales(
040: "normal StoreMem", Factory.createGraphMem());
041: new TestStoreSpeed("vladimir taltos").gonzales("GraphMem",
042: Factory.createGraphMem());
043: }
044:
045: private void mark() {
046: began = System.currentTimeMillis();
047: }
048:
049: static final int COUNT = 100000;
050:
051: private Triple newt(int i) {
052: return new Triple(node("s" + (i % 1000)), node("p"
053: + ((i + 11) % 20)), node("s" + ((i + 131) % 1001)));
054: }
055:
056: private void makeTriples() {
057: for (int i = 0; i < COUNT; i += 1)
058: newt(i);
059: }
060:
061: private void fillGraph(Graph g) {
062: for (int i = 0; i < COUNT; i += 1)
063: g.add(newt(i));
064: }
065:
066: private long ticktock(String title) {
067: long ticks = System.currentTimeMillis() - began;
068: System.err.println("+ " + title + " took: " + ticks + "ms.");
069: mark();
070: return ticks;
071: }
072:
073: private void consumeAll(Graph g) {
074: int count = 0;
075: ClosableIterator it = g.find(node("s500"), null, null);
076: while (it.hasNext()) {
077: it.next();
078: count += 1; /* if (count %1000 == 0) System.err.print( (count / 1000) %10 ); */
079: }
080: // System.err.println( "| we have " + count + " triples." );
081: // assertEquals( g.size(), count );
082: }
083:
084: private void gonzales(String title, Graph g) {
085: System.err.println("");
086: System.err.println("| gonzales: " + title);
087: mark();
088: makeTriples();
089: ticktock("generating triples");
090: makeTriples();
091: ticktock("generating triples again");
092: makeTriples();
093: long gen = ticktock("generating triples yet again");
094: fillGraph(g);
095: long fill = ticktock("filling graph");
096: System.err.println("> insertion time: " + (fill - gen));
097: fillGraph(g);
098: ticktock("adding the same triples again");
099: consumeAll(g);
100: ticktock("counting s500 triples");
101: consumeAll(g);
102: ticktock("counting s500 triples again");
103: consumeAll(g);
104: ticktock("counting s500 triples yet again");
105: }
106: }
107:
108: /*
109: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
110: All rights reserved.
111:
112: Redistribution and use in source and binary forms, with or without
113: modification, are permitted provided that the following conditions
114: are met:
115:
116: 1. Redistributions of source code must retain the above copyright
117: notice, this list of conditions and the following disclaimer.
118:
119: 2. Redistributions in binary form must reproduce the above copyright
120: notice, this list of conditions and the following disclaimer in the
121: documentation and/or other materials provided with the distribution.
122:
123: 3. The name of the author may not be used to endorse or promote products
124: derived from this software without specific prior written permission.
125:
126: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
127: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
128: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
129: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
130: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
131: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
132: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
133: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
134: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
135: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
136: */
|