Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 65355 Details for
Bug 160389
[api] change how offline task data is cached to disk and refactor attribute factory
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Updated version of PersistenceTest with a few changes to improve db4o's performance.
PersistenceTest.java (text/plain), 4.56 KB, created by
Ismael Juma
on 2007-04-29 19:33:15 EDT
(
hide
)
Description:
Updated version of PersistenceTest with a few changes to improve db4o's performance.
Filename:
MIME Type:
Creator:
Ismael Juma
Created:
2007-04-29 19:33:15 EDT
Size:
4.56 KB
patch
obsolete
>package db4o; > >import java.io.Serializable; > >import com.db4o.Db4o; >import com.db4o.ObjectContainer; >import com.db4o.ObjectSet; >import com.db4o.config.annotations.Indexed; >import com.db4o.query.Query; > >public class PersistenceTest { > > public static void main(String[] args) throws Exception { > testbdb(); > testLucene(); > testdb4o(); > } > > private static void testbdb() throws DatabaseException, > UnsupportedEncodingException { > long l1 = System.currentTimeMillis(); > > EnvironmentConfig envConfig = new EnvironmentConfig(); > envConfig.setAllowCreate(true); > > Environment env = new Environment(new File("bdb.database"), envConfig); > > DatabaseConfig dbConfig = new DatabaseConfig(); > dbConfig.setAllowCreate(true); > > Database db = env.openDatabase(null, "bdb.database", dbConfig); > > ClassCatalog catalog = new StoredClassCatalog(db); > EntryBinding binding = new SerialBinding(catalog, Simple.class); > > for (int i = 0; i < 1000; i++) { > Simple simple = new Simple("group", "foo " + i, i); > > DatabaseEntry key = new DatabaseEntry(Integer.toString(i).getBytes( > "UTF-8")); > DatabaseEntry data = new DatabaseEntry(); > > binding.objectToEntry(simple, data); > > db.put(null, key, data); > } > > long l2 = System.currentTimeMillis(); > System.err.println("bdb: " + (l2 - l1) / 1000f); > > // need to use "secondary database" for retrieving by "group" field > for (int i = 0; i < 1000; i++) { > DatabaseEntry key = new DatabaseEntry(Integer.toString(i).getBytes( > "UTF-8")); > DatabaseEntry data = new DatabaseEntry(); > > if (db.get(null, key, data, LockMode.DEFAULT) != OperationStatus.SUCCESS) { > System.err.println("Can't find " + i); > } > } > long l3 = System.currentTimeMillis(); > System.err.println("bdb: " + (l3 - l2) / 1000f); > > db.close(); > } > > private static void testLucene() throws IOException { > IndexWriter w = new IndexWriter("lucene.database", > new SimpleAnalyzer(), true); > > long l1 = System.currentTimeMillis(); > for (int i = 0; i < 1000; i++) { > Document doc = new Document(); > doc.add(new Field("group", "group", Field.Store.YES, > Field.Index.UN_TOKENIZED)); > doc.add(new Field("foo", "foo " + i, Field.Store.YES, > Field.Index.UN_TOKENIZED)); > doc.add(new Field("n", Integer.toString(i), Field.Store.YES, > Field.Index.UN_TOKENIZED)); > > w.updateDocument(new Term("n", Integer.toString(i)), doc); > } > > w.optimize(); > w.close(); > > long l2 = System.currentTimeMillis(); > System.err.println("lucene: " + (l2 - l1) / 1000f); > > IndexReader r = IndexReader.open("lucene.database"); > IndexSearcher s = new IndexSearcher(r); > PhraseQuery q = new PhraseQuery(); > q.add(new Term("group", "group")); > Hits hits = s.search(q); > > if (hits.length() != 1000) { > System.err.println("lucene: Invalid search result"); > } > > long l3 = System.currentTimeMillis(); > System.err.println("lucene: " + (l3 - l2) / 1000f); > } > > private static void testdb4o() { > /* > * Set flushFileBuffers to false. This doesn't affect this test much, > * but the performance of db4o suffers a lot on Windows if this is true > * because it causes db4o to flush the disk after each commit. > */ > Db4o.configure().flushFileBuffers(false); > ObjectContainer db = Db4o.openFile("db4o.database"); > > long l1 = System.currentTimeMillis(); > for (int i = 0; i < 1000; i++) { > final Simple s = new Simple("group", "foo " + i, i); > > /* Query on n only to match what the Lucene version does */ > Query query = db.query(); > query.constrain(Simple.class); > query.descend("n").constrain(s.n); > ObjectSet<?> set = query.execute(); > > if (set.hasNext()) { > db.set(set.next()); > } else { > db.set(s); > } > } > > db.commit(); > > long l2 = System.currentTimeMillis(); > System.err.println("db4o: " + (l2 - l1) / 1000f); > > /* > * Use SODA query for best performance. Native queries are converted > * into SODA queries through bytecode instrumentation where possible > * and don't involve Strings, but I wanted to eliminate the possibility > * that this was not happening (for whatever reason). > */ > Query query = db.query(); > query.constrain(Simple.class); > query.descend("group").constrain("group");//$NON-NLS-1$ > ObjectSet<?> set = query.execute(); > > if (set.size() != 1000) { > System.err.println("db4o: Invalid search result " + set.size()); > } > > long l3 = System.currentTimeMillis(); > System.err.println("db4o: " + (l3 - l2) / 1000f); > > db.close(); > } > > private static final class Simple implements Serializable { > @Indexed > String group; > String foo; > @Indexed > int n; > > public Simple(String group, String foo, int n) { > this.group = group; > this.foo = foo; > this.n = n; > } > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 160389
:
64548
| 65355 |
71577
|
71578
|
71639
|
71646
|
71653
|
71660
|
71670
|
71673