Skip to content

Commit

Permalink
Changed output to print millis and log results
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Herrera <[email protected]>
  • Loading branch information
JogahCR committed Dec 21, 2013
1 parent 71bfe68 commit 6137222
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
49 changes: 30 additions & 19 deletions ORM-Benchmark/src/com/littleinc/orm_benchmark/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ShareCompat.IntentBuilder;
import android.text.Html;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.Button;
Expand All @@ -37,6 +39,8 @@ public class MainActivity extends FragmentActivity {

private int mCount = 0;

private String mResults;

private Button mShowResultsBtn;

private BenchmarkExecutable[] mOrms = new BenchmarkExecutable[] {
Expand All @@ -55,6 +59,31 @@ protected void onCreate(Bundle savedInstanceState) {
}

public void showGlobalResults(View v) {
ResultDialog dialog = ResultDialog.newInstance(R.string.results_title,
mResults);
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.add(dialog, ResultDialog.class.getSimpleName());
tx.commit();
}

public void runBenchmark(View v) {
if (mCount < NUM_ITERATIONS) {
v.setEnabled(false);
mShowResultsBtn.setEnabled(false);

new ProfilerTask(v).execute(CREATE_DB, WRITE_DATA, READ_DATA,
READ_INDEXED, READ_SEARCH, DROP_DB);
} else {
mResults = buildResults();
Log.d(MainActivity.class.getSimpleName(), "Results:\n" + mResults);

mCount = 0;
v.setEnabled(true);
mShowResultsBtn.setEnabled(true);
}
}

private String buildResults() {
StringBuilder builder = new StringBuilder();
tasks: for (Task task : Task.values()) {
builder.append("<b>Task ").append(task).append("</b><br />");
Expand All @@ -81,25 +110,7 @@ public void showGlobalResults(View v) {
}
builder.append("<br />");
}
ResultDialog dialog = ResultDialog.newInstance(R.string.results_title,
builder.toString());
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.add(dialog, ResultDialog.class.getSimpleName());
tx.commit();
}

public void runBenchmark(View v) {
if (mCount < NUM_ITERATIONS) {
v.setEnabled(false);
mShowResultsBtn.setEnabled(false);

new ProfilerTask(v).execute(CREATE_DB, WRITE_DATA, READ_DATA,
READ_INDEXED, READ_SEARCH, DROP_DB);
} else {
mCount = 0;
v.setEnabled(true);
mShowResultsBtn.setEnabled(true);
}
return builder.toString();
}

private class ProfilerTask extends AsyncTask<Task, Void, Void> {
Expand Down
6 changes: 2 additions & 4 deletions ORM-Benchmark/src/com/littleinc/orm_benchmark/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public static String getRandomString(int length) {
}

/**
* @return mm:ss.millis
* @return millis
*/
public static String formatElapsedTime(long nanos) {
return String.format("%s:%s.%s", TimeUnit.NANOSECONDS.toMinutes(nanos),
TimeUnit.NANOSECONDS.toSeconds(nanos),
String.format("%04d", TimeUnit.NANOSECONDS.toMillis(nanos)));
return String.valueOf(TimeUnit.NANOSECONDS.toMillis(nanos));
}
}

0 comments on commit 6137222

Please sign in to comment.