Skip to content

Instantly share code, notes, and snippets.

@ryanswanstrom
Created December 3, 2010 21:37
Show Gist options
  • Save ryanswanstrom/727600 to your computer and use it in GitHub Desktop.
Save ryanswanstrom/727600 to your computer and use it in GitHub Desktop.
This is a file for testing the speed of OrientDB
package orienttest;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.graph.ODatabaseGraphTx;
import com.orientechnologies.orient.core.db.graph.OGraphVertex;
import com.orientechnologies.orient.core.db.object.ODatabaseObjectTx;
import com.orientechnologies.orient.core.db.record.ODatabaseColumn;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ORecordColumn;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
/**
* This class is for testing the speed of OrientDB
*/
public class OrientDBSpeed {
enum TYPE {GRAPH, OBJECT, COLUMN, DOCUMENT};
public static void main(String[] args) {
OrientDBSpeed setup = new OrientDBSpeed();
int num = 150000;
System.out.println("Number of inserts: " + num);
setup.setupColDB(num);
setup.setupDocDB(num);
setup.setupObjDB(num);
setup.setupGraphDB(num);
}
private void printElapsed(TYPE type, double start, double end) {
double total = ((end - start)/1000000000d);
System.out.format(type + ": Total time is %f seconds. %n", total);
}
public void setupColDB(int num) {
ODatabaseColumn db = new ODatabaseColumn("memory:coldb").create();
db.declareIntent(new OIntentMassiveInsert());
ORecordColumn record = new ORecordColumn(db);
db.begin(TXTYPE.NOTX);
long start = System.nanoTime();
for (int i = 0; i < num; i++) {
record.reset();
record.add("Gipsy");
record.add("Cat");
record.add("European");
record.add("Italy");
record.save();
if (i%12 == 0) {
db.commit();
db.begin(TXTYPE.NOTX);
}
}
db.commit();
long end = System.nanoTime();
this.printElapsed(TYPE.COLUMN, start, end);
db.declareIntent(null);
db.close();
}
public void setupDocDB(int num) {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:testDocDB").create();
db.declareIntent(new OIntentMassiveInsert());
db.begin();
long start = System.nanoTime();
for (int i = 0; i < num; i++) {
ODocument doc = db.newInstance();
doc.setClassName("Log");
doc.field("d", "t");
// SAVE THE DOCUMENT
doc.save();
if (i%12 == 0) {
db.commit();
db.begin();
}
}
long end = System.nanoTime();
this.printElapsed(TYPE.DOCUMENT, start, end);
db.declareIntent(null);
db.commit();
// for (ODocument logs : db.browseCluster("Log")) {
// System.out.println(logs.field("proj"));
// }
// for (ODocument person : db.browseCluster("Person")) {
// System.out.println(person.field("name"));
// }
//
// for (ODocument animal : db.browseClass("Log")) {
// System.out.println(animal.field("proj"));
// }
// for (ODocument animal : db.browseClass("Person")) {
// System.out.println(animal.field("name"));
// }
// long logs = db.countClass("Log");
// System.out.println("DocDB Log class count: " + logs);
db.close();
}
public void setupObjDB(int num) {
ODatabaseObjectTx db = new ODatabaseObjectTx("memory:objdb").create();
db.declareIntent(new OIntentMassiveInsert());
long start = System.nanoTime();
for (int i = 0; i < num; i++) {
LogIt logIt = new LogIt();
logIt.level = 6;
logIt.project = "My Class";
logIt.title = "Some great title";
db.save(logIt);
}
long end = System.nanoTime();
this.printElapsed(TYPE.OBJECT, start, end);
// long logs = db.countClass("LogIt");
// System.out.println("Obj Log class count: " + logs);
db.declareIntent(null);
db.close();
}
public void setupGraphDB(int num) {
ODatabaseGraphTx db = new ODatabaseGraphTx("memory:graphdb").create();
db.declareIntent(new OIntentMassiveInsert());
OGraphVertex rootNode = db.createVertex().set("id", 0);
OGraphVertex currentNode = rootNode;
db.setRoot("graph", rootNode);
long start = System.nanoTime();
for (int i = 1; i < num; ++i) {
OGraphVertex newNode = db.createVertex().set("id", i).set("level", i + 3);
currentNode.link(newNode);
currentNode = newNode;
}
long end = System.nanoTime();
this.printElapsed(TYPE.GRAPH, start, end);
db.declareIntent(null);
db.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment