Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ORM-Benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="com.littleinc.orm_benchmark.Application" >
android:theme="@style/AppTheme">
<activity
android:name="com.littleinc.orm_benchmark.MainActivity"
android:label="@string/app_name" >
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ enum Task {
CREATE_DB, WRITE_DATA, READ_DATA, READ_INDEXED, READ_SEARCH, DROP_DB;
}

int getProfilerId();

String getOrmName();

void init(Context context, boolean useInMemoryDb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

public class MainActivity extends FragmentActivity {

private static final boolean USE_IN_MEMORY_DB = true;

private static final int NUM_ITERATIONS = 5;

private int mCount = 0;
Expand All @@ -44,20 +46,30 @@ public class MainActivity extends FragmentActivity {
private Button mShowResultsBtn;

private BenchmarkExecutable[] mOrms = new BenchmarkExecutable[] {
SQLiteExecutor.INSTANCE,
OptimizedSQLiteExecutor.INSTANCE,
ORMLiteExecutor.INSTANCE,
GreenDaoExecutor.INSTANCE };
new SQLiteExecutor(),
new OptimizedSQLiteExecutor(),
new ORMLiteExecutor(),
new GreenDaoExecutor() };

private boolean mWasInitialized = false;

private SparseArray<Map<Task, List<Long>>> mGlobalResults;
private Map<String, Map<Task, List<Long>>> mGlobalResults;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mGlobalResults = new SparseArray<Map<Task, List<Long>>>();
mGlobalResults = new HashMap<>();
mShowResultsBtn = (Button) findViewById(R.id.show_results_btn);

if (!mWasInitialized) {
for (BenchmarkExecutable orm : mOrms) {
orm.init(this, USE_IN_MEMORY_DB);
}

mWasInitialized = true;
}
}

public void showGlobalResults(View v) {
Expand Down Expand Up @@ -96,8 +108,8 @@ private String buildResults() {
builder.append("<b>Task ").append(task).append("</b><br />");
orms: for (BenchmarkExecutable orm : mOrms) {

Map<Task, List<Long>> results = mGlobalResults.get(orm
.getProfilerId());
Map<Task, List<Long>> results = mGlobalResults.get(orm.getOrmName());

if (results == null) {
continue orms;
}
Expand Down Expand Up @@ -134,7 +146,7 @@ protected Void doInBackground(Task... params) {
for (Task task : params) {
try {
long result = 0;
int profilerId = item.getProfilerId();

switch (task) {
case CREATE_DB:
result = item.createDbStructure();
Expand All @@ -155,7 +167,7 @@ protected Void doInBackground(Task... params) {
result = item.writeWholeData();
break;
}
addProfilerResult(profilerId, task, result);
addProfilerResult(item.getOrmName(), task, result);
} catch (SQLException e) {
e.printStackTrace();
continue;
Expand All @@ -170,17 +182,16 @@ protected void onPostExecute(Void result) {
runBenchmark(mView);
};

private void addProfilerResult(int profilerId, Task task, long result) {
Map<Task, List<Long>> profilerResults = mGlobalResults
.get(profilerId);
private void addProfilerResult(String benchmarkName, Task task, long result) {
Map<Task, List<Long>> profilerResults = mGlobalResults.get(benchmarkName);
if (profilerResults == null) {
profilerResults = new HashMap<Task, List<Long>>();
profilerResults = new HashMap<>();
profilerResults.put(task, new LinkedList<Long>());
mGlobalResults.put(profilerId, profilerResults);
mGlobalResults.put(benchmarkName, profilerResults);
}
List<Long> resultPerTask = profilerResults.get(task);
if (resultPerTask == null) {
resultPerTask = new LinkedList<Long>();
resultPerTask = new LinkedList<>();
profilerResults.put(task, resultPerTask);
}
resultPerTask.add(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@
import com.littleinc.orm_benchmark.greendao.MessageDao.Properties;
import com.littleinc.orm_benchmark.util.Util;

public enum GreenDaoExecutor implements BenchmarkExecutable {
public class GreenDaoExecutor implements BenchmarkExecutable {

INSTANCE;
private static final String TAG = "GreenDaoExecutor";

private static String DB_NAME = "greendao_db";

private DataBaseHelper mHelper;

private DaoMaster mDaoMaster;

@Override
public int getProfilerId() {
return 3;
}

@Override
public void init(Context context, boolean useInMemoryDb) {
Log.d(TAG, "Creating DataBaseHelper");
mHelper = new DataBaseHelper(context, (useInMemoryDb ? null : DB_NAME),
null);
}
Expand Down Expand Up @@ -61,12 +57,9 @@ public long writeWholeData() throws SQLException {
newMessage.setSorted_by(Double.valueOf(System.nanoTime()));
newMessage.setContent(Util.getRandomString(100));
newMessage.setClient_id(System.currentTimeMillis());
newMessage
.setSender_id(Math.round(Math.random() * NUM_USER_INSERTS));
newMessage.setChannel_id(Math.round(Math.random()
* NUM_USER_INSERTS));
newMessage
.setCreated_at((int) (System.currentTimeMillis() / 1000L));
newMessage.setSender_id(Math.round(Math.random() * NUM_USER_INSERTS));
newMessage.setChannel_id(Math.round(Math.random() * NUM_USER_INSERTS));
newMessage.setCreated_at((int) (System.currentTimeMillis() / 1000L));

messages.add(newMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
import com.littleinc.orm_benchmark.BenchmarkExecutable;
import com.littleinc.orm_benchmark.util.Util;

public enum ORMLiteExecutor implements BenchmarkExecutable {

INSTANCE;
public class ORMLiteExecutor implements BenchmarkExecutable {

private static final String TAG = "ORMLiteExecutor";

private DataBaseHelper mHelper;

@Override
public void init(Context context, boolean useInMemoryDb) {
Log.d(TAG, "Creating DataBaseHelper");
DataBaseHelper.init(context, useInMemoryDb);
mHelper = DataBaseHelper.getInstance();
}
Expand Down Expand Up @@ -72,14 +73,12 @@ public long writeWholeData() throws SQLException {
for (User user : users) {
User.getDao().createOrUpdate(user);
}
Log.d(ORMLiteExecutor.class.getSimpleName(), "Done, wrote "
+ NUM_USER_INSERTS + " users");
Log.d(TAG, "Done, wrote " + NUM_USER_INSERTS + " users");

for (Message message : messages) {
Message.getDao().createOrUpdate(message);
}
Log.d(ORMLiteExecutor.class.getSimpleName(), "Done, wrote "
+ NUM_MESSAGE_INSERTS + " messages");
Log.d(TAG, "Done, wrote " + NUM_MESSAGE_INSERTS + " messages");

db.setTransactionSuccessful();
} finally {
Expand All @@ -91,7 +90,7 @@ public long writeWholeData() throws SQLException {
@Override
public long readWholeData() throws SQLException {
long start = System.nanoTime();
Log.d(ORMLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, " + mHelper.getDao(Message.class).queryForAll().size()
+ " rows");
return System.nanoTime() - start;
Expand All @@ -100,7 +99,7 @@ public long readWholeData() throws SQLException {
@Override
public long readIndexedField() throws SQLException {
long start = System.nanoTime();
Log.d(ORMLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, "
+ mHelper
.getDao(Message.class)
Expand All @@ -113,11 +112,11 @@ public long readIndexedField() throws SQLException {
public long readSearch() throws SQLException {
SelectArg arg = new SelectArg("%" + SEARCH_TERM + "%");
long start = System.nanoTime();
Log.d(ORMLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, "
+ mHelper.getDao(Message.class).queryBuilder()
.limit(SEARCH_LIMIT).where()
.like(Message.CONTENT, arg).query().size()
.limit(SEARCH_LIMIT).where()
.like(Message.CONTENT, arg).query().size()
+ " rows");
return System.nanoTime() - start;
}
Expand All @@ -131,11 +130,6 @@ public long dropDb() throws SQLException {
return System.nanoTime() - start;
}

@Override
public int getProfilerId() {
return 2;
}

@Override
public String getOrmName() {
return "ORMLite";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@
import java.util.LinkedList;
import java.util.List;

public enum SQLiteExecutor implements BenchmarkExecutable {

INSTANCE;

/**
* An unoptimized set of SQLite operations for reading and writing the test database objects.
*
* See {@link com.littleinc.orm_benchmark.sqliteoptimized.OptimizedSQLiteExecutor} for optimized
* versions of these SQLite operations.
*/
public class SQLiteExecutor implements BenchmarkExecutable {

private static final String TAG = "SQLiteExecutor";

private DataBaseHelper mHelper;

@Override
public int getProfilerId() {
return 1;
}

@Override
public String getOrmName() {
return "RAW";
}

@Override
public void init(Context context, boolean useInMemoryDb) {
Log.d(TAG, "Creating DataBaseHelper");
mHelper = new DataBaseHelper(context, useInMemoryDb);
}

Expand Down Expand Up @@ -65,14 +67,12 @@ public long writeWholeData() throws SQLException {
for (User user : users) {
db.insert(User.TABLE_NAME, null, user.prepareForInsert());
}
Log.d(SQLiteExecutor.class.getSimpleName(), "Done, wrote "
+ NUM_USER_INSERTS + " users");
Log.d(TAG, "Done, wrote " + NUM_USER_INSERTS + " users");

for (Message message : messages) {
db.insert(Message.TABLE_NAME, null, message.prepareForInsert());
}
Log.d(SQLiteExecutor.class.getSimpleName(), "Done, wrote "
+ NUM_MESSAGE_INSERTS + " messages");
Log.d(TAG, "Done, wrote " + NUM_MESSAGE_INSERTS + " messages");
db.setTransactionSuccessful();
} finally {
db.endTransaction();
Expand Down Expand Up @@ -109,7 +109,7 @@ public long readWholeData() throws SQLException {

messages.add(newMessage);
}
Log.d(SQLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, " + messages.size() + " rows");
} finally {
if (c != null) {
Expand Down Expand Up @@ -148,7 +148,7 @@ public long readIndexedField() throws SQLException {
newMessage.setSortedBy(c.getDouble(c
.getColumnIndex(Message.SORTED_BY)));

Log.d(SQLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, " + c.getCount() + " rows");
}
} finally {
Expand Down Expand Up @@ -191,7 +191,7 @@ public long readSearch() throws SQLException {

messages.add(newMessage);
}
Log.d(SQLiteExecutor.class.getSimpleName(),
Log.d(TAG,
"Read, " + messages.size() + " rows");
} finally {
if (c != null) {
Expand Down
Loading