jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1225957 - in /incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev: Jena175_TDB_prefixes.java Run.java
Date Fri, 30 Dec 2011 22:46:45 GMT
Author: andy
Date: Fri Dec 30 22:46:44 2011
New Revision: 1225957

URL: http://svn.apache.org/viewvc?rev=1225957&view=rev
Log: (empty)

Added:
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena175_TDB_prefixes.java
Modified:
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java

Added: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena175_TDB_prefixes.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena175_TDB_prefixes.java?rev=1225957&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena175_TDB_prefixes.java (added)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Jena175_TDB_prefixes.java Fri Dec 30
22:46:44 2011
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dev;
+
+import java.util.Map ;
+
+import org.openjena.riot.SysRIOT ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
+import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage ;
+import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.TDBFactory ;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB ;
+import com.hp.hpl.jena.tdb.sys.DatasetControlNone ;
+import com.hp.hpl.jena.tdb.sys.SetupTDB ;
+import com.hp.hpl.jena.util.FileManager ;
+
+public class Jena175_TDB_prefixes
+{
+    public static void main(String ... argv)
+    {
+        // Err - the prefixes don't go anywhere!
+        // They go into the parser profile and are lost.
+        
+        SysRIOT.wireIntoJena() ;
+        DatasetGraphTDB dsg = (DatasetGraphTDB)TDBFactory.createDatasetGraph() ;
+        Dataset ds = DatasetFactory.create(dsg) ;
+        FileManager.get().readModel(ds.getDefaultModel(), "D.ttl") ;
+        TDB.sync(ds) ;
+        System.out.println("Prefixes:") ;
+        DatasetPrefixStorage prefixes = SetupTDB.makePrefixes(dsg.getLocation(), SetupTDB.globalConfig,
new DatasetControlNone()) ;
+        for ( String gn : prefixes.graphNames() )
+        {
+            System.out.println("Graph: "+gn) ;
+            PrefixMapping pmap = prefixes.getPrefixMapping(gn) ;
+            Map<String, String> x = pmap.getNsPrefixMap() ;
+            for ( String k : x.keySet() )
+                System.out.printf("  %-10s %s\n", k+":", x.get(k)) ;
+        }
+       
+        
+    }
+}
+

Modified: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java?rev=1225957&r1=1225956&r2=1225957&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java (original)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dev/Run.java Fri Dec 30 22:46:44 2011
@@ -21,8 +21,12 @@ package dev;
 import java.io.File ;
 import java.io.FileInputStream ;
 import java.io.InputStream ;
+import java.nio.ByteBuffer ;
+import java.util.UUID ;
 
 import org.junit.Test ;
+import org.openjena.atlas.io.BlockUTF8 ;
+import org.openjena.atlas.lib.Bytes ;
 import org.openjena.atlas.lib.FileOps ;
 import org.openjena.atlas.lib.Lib ;
 import org.openjena.atlas.logging.Log ;
@@ -33,6 +37,7 @@ import com.hp.hpl.jena.rdf.model.RDFRead
 import com.hp.hpl.jena.sparql.function.FunctionRegistry ;
 import com.hp.hpl.jena.sparql.function.library.wait ;
 import com.hp.hpl.jena.sparql.lang.SyntaxVarScope ;
+import com.hp.hpl.jena.sparql.util.Timer ;
 import com.hp.hpl.jena.tdb.DatasetGraphTxn ;
 import com.hp.hpl.jena.tdb.StoreConnection ;
 import com.hp.hpl.jena.tdb.TDBFactory ;
@@ -44,11 +49,80 @@ public class Run extends RunBase
 {
     static { Log.setLog4j() ; }
     
+    static int N = 1000000;
+    
     public static void main(String[] argv) throws Exception
     {
+        timeConvertingStrings() ;
+        exit(0) ;
         prefixesAndTDB() ;
+        
     }
     
+    private static void timeConvertingStrings() throws Exception
+    {
+        String[] x = new String[N] ;
+        
+        for ( int i = 0 ; i < N ; i++ )
+            x[i] = randomString() ;
+        
+        System.out.println("Waiting") ;
+        System.in.read();
+        
+        for ( int i = 0 ; i < 10 ; i++ )
+        {
+            foo(x) ;
+            System.out.println() ;
+        }
+    }
+        
+    public static void foo(String[] x)
+    {
+        
+        ByteBuffer bb[] = new ByteBuffer[N] ;
+        for ( int i = 0 ; i < N ; i++ )
+            bb[i] = ByteBuffer.allocate(100*4) ;
+        
+        Timer t1 = new Timer() ;
+        t1.startTimer() ;
+        for ( int i = 0 ; i < N ; i++ )
+        {
+            Bytes.toByteBuffer(x[i], bb[i]) ;
+            bb[i].flip() ;
+        }
+        for ( int i = 0 ; i < N ; i++ )
+            Bytes.fromByteBuffer(bb[i]) ;
+        
+        long time1 = t1.endTimer() ;
+        System.out.println(Timer.timeStr(time1)) ;
+
+        for ( int i = 0 ; i < N ; i++ )
+            bb[i] = ByteBuffer.allocate(100*4) ;
+
+
+        Timer t2 = new Timer() ;
+        t2.startTimer() ;
+        for ( int i = 0 ; i < N ; i++ )
+        {
+            BlockUTF8.fromChars(x[i], bb[i]) ;    // faster.
+            bb[i].flip() ;
+        }
+
+        for ( int i = 0 ; i < N ; i++ )           // Slower
+            BlockUTF8.toString(bb[i]) ;
+        
+        long time2 = t2.endTimer() ;
+        System.out.println(Timer.timeStr(time2)) ;
+        
+    }
+    
+    private static int i = 0 ; 
+    private static String randomString()
+    {
+        i++ ;
+        return "http://jena.apache.org/abc"+UUID.randomUUID() ;
+    }
+
     public static void prefixesAndTDB() throws Exception
     {
         Dataset ds = TDBFactory.createDataset( "DB" ) ; // tdbDest is a String



Mime
View raw message