title: Realm taking more time for read and write then SQLite
body: <p>I am trying to replace SQLite with Realm in an android application.</p>
  
  <p>Following is pseudo code of how I am trying to do it:</p>
  
  <pre><code>//SQLite Insert
  public void deleteExistingAndInsertNewItemsInDb(ArrayList&lt;Item&gt; itemList, int userId) {
      Log.d("REALM_TEST", "No. of Records :: " + itemList.size());
      long start;
      if (itemList != null &amp;&amp; itemList.size() &gt; 0) {
          start = System.nanoTime();
          initializeDb();
          db.beginTransaction();
          // delete existing items from the item list table for the provided userId
          db.delete(DataBaseHelper.TABLE_NAME, DataBaseHelper.USER_ID + "=" + userId, null);
          // insert new item list into local DB.
          for(Item item : itemList) {
              ContentValues contentValues = new ContentValues();
              contentValues.put(DataBaseHelper.COL1, item.getProperty1());
              contentValues.put(DataBaseHelper.COL2, item.getProperty2());
              ...
              ...
              contentValues.put(DataBaseHelper.COL50, item.getProperty50());
              // insert item details into local DB.
              db.insert(DataBaseHelper.TABLE_NAME, null, contentValues);
          }
          db.setTransactionSuccessful();
          db.endTransaction();
          // close database.
          closeDb();
          long sum = System.nanoTime() - start;
          Log.d("REALM_TEST", "Sqlite Insert :: " + sum/1000000);
      }
  }  
  
  
  //SQLite Read
  public ArrayList&lt;Item&gt; getItemListFromDB(int userId){
  
      ArrayList&lt;Item&gt; itemList = new ArrayList&lt;&gt;();
      initializeDb();
      long start = System.nanoTime();
      Cursor cursor = db.query(DataBaseHelper.TABLE_NAME, DataBaseHelper.COLUMN_LIST, DataBaseHelper.USER_ID + "=" + userId,
              null, null, null, null);
      if(cursor != null) {
          while(cursor.moveToNext()) {
              Item item= new Item();
              item.setProperty1(cursor.getString(0));
              item.setProperty2(cursor.getString(1));
              ...
              ...
              ...
              item.setProperty50(cursor.getString(50));
  
              itemList.add(item);
          }
      }
      closeDb();
      sum = System.nanoTime()-start;
      Log.d("REALM_TEST", "Sqlite read list :: " + sum / 1000000 + "ms For " + itemList.size() + " records");
      return itemList;
  }
  
  //Realm Insert
  public void deleteExistingAndInsertNewItemsInRealm(ArrayList&lt;Item&gt; itemList, int userId) {
  
      Realm realm = Realm.getInstance(Application.getContext());
      long start = System.nanoTime();
      //delete all objects
      RealmResults&lt;RealmItem&gt; results = realm.where(RealmItem.class).findAll();
      realm.beginTransaction();
      results.clear();
  
      for (Item item : itemList) {
          RealmItem realmItem = realm.createObject(RealmItem.class);
          realmItem.setProperty1(item.getProperty1());
          realmItem.setProperty2(item.getProperty2());
          ...
          ...
          realmItem.setProperty50(item.getProperty50());
      }
      realm.commitTransaction();
      long sum = System.nanoTime() - start;
      Log.d("REALM_TEST", "Realm Insert :: " + sum/1000000);
  }
  
  
  //Realm Read
  public ArrayList&lt;Item&gt; getItemListFromRealm(int userId) {
  
      ArrayList&lt;Item&gt; itemList = new ArrayList&lt;&gt;();
      Realm realm = Realm.getInstance(Application.getContext());
      long start = System.nanoTime();
      RealmResults&lt;RealmItem&gt; results =  realm.where(RealItem.class)
              .equalTo("USER_ID", userId).findAll();
      if(results != null) {
          for (RealItem result: results)  {
  
              Item item= new Item();
              item.setProperty1(result.getProperty1());
              item.setProperty2(cursor.getProperty2());
              ...
              ...
              ...
              item.setProperty50(cursor.getProperty50());
  
              itemList.add(item);
          }
      }
      sum = System.nanoTime()-start;
      Log.d("REALM_TEST", "Realm read list :: " + sum / 1000000 + "ms For " + itemList.size() + " records");
      return itemList;
  }
  </code></pre>
  
  <p>for 500 items following is read write time in milli seconds:</p>
  
  <pre><code>+--------+-------+--------+-------+
  |  Write         | Read           |
  +--------+-------+--------+-------+
  | Sqlite | Realm | Sqlite | Realm |
  | 247    | 382   | 142    | 222   |
  | 303    | 321   | 102    | 278   |
  | 263    | 303   | 134    | 240   |
  | 301    | 292   | 165    | 290   |
  +--------+-------+--------+-------+
  </code></pre>
  
  <p>Am i doing something wrong?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I have added a working example <a href="https://github.com/rahul01/RealmTest.git" rel="nofollow">here</a>. write times are almost similar to my actual app. read times have improved in the example, for realm. </p>
  
  <p>I am using a single data type String for all properties in the example where as its a good mix of data types in actual application.</p>