Getting Started With TestIndex Benchmark For Android

Android is Google's new free mobile platform based on Linux. It provides Java as its main application development language (and includes the Dalvik virtual machine, which is optimized for mobile devices). Right now no actual devices use this platform, but the SDK is available and developers can write applications for the platform and run them in its emulator.

Android is neither Java ME (J2ME)- nor J2SE-compatible. It provides its own framework of classes, but most of the Java 1.6 SE classes are present here, so it is possible to use Perst version 1.5 under Android. Although Android includes a built-in database system, SQLite, Perst provides better performance (almost ten times better in our TestIndex benchmark test) and of course, Perst delivers the benefits of object orientation, including a seamless interface with application objects, and the ability to persist complex data structures.

Although the perst15.jar library can be used under Android without any changes, there is one aspect which should be noted. For some reason, Android's java.io.RandomAccessFile class is not able to create file even in write mode. This seems to be a bug, and will likely be fixed in the next release of Android, but right now the problem can be fixed by explicitly creating the file using the android.app.Activity.openFileOutput method:


        String databasePath = "testindex.dbs";
        try { 
            // It is necessary to create file using Activity.openFileUutput method otherwise
            // java.io.RandomAccessFile will not able to open it (even in write mode). It seems to be a bug
            // which I expect to be fixed in next release of Android, but right now these two lines fix
            // this problem.
            this.openFileOutput(databasePath, 0).close();
            databasePath = getFileStreamPath(databasePath).getAbsolutePath();	
        } catch (IOException x) {}

        // Get instance of Perst storage
        Storage db = StorageFactory.getInstance().createStorage();

        // Open the database with given database name and specified page pool (database cache) size
        db.open(databasePath, pagePoolSize);

This Perst distributive includes a port of the Perst TestIndex benchmark to the Android platform. TestIndex.java is a very simple benchmark measuring performance of basic database operation: inserting, searching and deleting records. It uses simple records with two primary key columns: one of 8-byte integer type and another of string type. These columns are assigned random values during database initialization. The benchmark consists of four steps:
  1. Insert data into the database. The number of inserted objects for the Android platform is 10000.
  2. Perform index searches for all objects using both indices.
  3. Iterate through all objects using index iterators.
  4. Locate and remove all objects one-by-one.

To allow comparison of Perst's performance with that of the built-in SQLite database system, this application includes a port of the benchmark for SQLite. The structure of the application is the following:

Benchmark.java
Main application class: makes it possible to user to start Perst or SQLite benchmark.
Test.java
Base class for all tests
PerstTest.java
Implementation of benchmark for Perst
SqlLiteTest.java
Implementation of benchmark for SQLite
ProgressMonitor.java
Class responsible for updating UI during test execution

To build and run this application you need to have the Eclipse IDE with an installed Android plugin. All necessary information about installing the Android plugin for Eclipse is available here.

To get started with the TestIndex benchmark, follow these steps:

  1. Download Perst and extract it to the root directory (so Perst will be located in \Perst). Perst can be installed in another place, but then you will need to adjust the path to perst15.jar in the Eclipse project settings.
  2. Import the Benchmark package to the workspace (Use the File/Import menu item and to start the import dialog, choose General/Existing Projects into workspace, then toggle Select root directory and specify perst/tst/android/Benchmark directory.
  3. Choose Run item in the menu and select Android Application. The Android emulator should be started and Benchmark application launched in it.
  4. Press the Menu button in the emulator, and a pop-up menu with Perst and SQLite items should appear (see screenshot). Choose which test you want to run. Please note that execution of the Perst test will take about 3 minutes and the SQLite test - about 20 minutes.

For support please e-mail [email protected] or visit our Perst support forum at http://forums.mcobject.com/.