public void count() { Log.i("DataStoreBenchmark", "Realm invoking count"); // super.intitalize(); Realm.deleteRealm(realmConfiguration); Realm realm; List<Long> values; long timeStart; values = new ArrayList<>(); realm = Realm.getInstance(realmConfiguration); add(realm); check(realm); for (int i = 0; i < numberOfIterations; i++) { System.gc(); timeStart = Debug.threadCpuTimeNanos(); long count = realm.where(Student.class).count(); long timeStop = Debug.threadCpuTimeNanos(); long duration = timeStop - timeStart; values.add(duration); } realm.beginTransaction(); realm.clear(Student.class); realm.commitTransaction(); realm.close(); finalvalues.put(COUNT, values); System.gc(); }
public void fullScan() { Log.i("DataStoreBenchmark", "Realm invoking full scan"); // super.intitalize(); Realm.deleteRealm(realmConfiguration); Realm realm; List<Long> values; long timeStart; values = new ArrayList<>(); realm = Realm.getInstance(realmConfiguration); add(realm); check(realm); for (int i = 0; i < numberOfIterations; i++) { System.gc(); timeStart = Debug.threadCpuTimeNanos(); RealmResults<Student> realmResults = realm .where(Student.class) .equalTo("csci", true) .between("points", 110, 120) .equalTo("name", "S1") .findAll(); long count = realmResults.size(); long timeStop = Debug.threadCpuTimeNanos(); long duration = timeStop - timeStart; values.add(duration); } realm.beginTransaction(); realm.clear(Student.class); realm.commitTransaction(); realm.close(); finalvalues.put(FULL_SCAN, values); Realm.deleteRealm(realmConfiguration); super.garbaceColl(); }
public void batchWrite() { Log.i("DataStoreBenchmark", "Realm invoking batch write"); // super.intitalize(); Realm.deleteRealm(realmConfiguration); Realm realm; List<Long> values; long timeStart; values = new ArrayList<>(); realm = Realm.getInstance(realmConfiguration); for (int j = 0; j < numberOfIterations; j++) { System.gc(); timeStart = Debug.threadCpuTimeNanos(); realm.beginTransaction(); for (int i = 0; i < numberOfObjects; i++) { Student student = realm.createObject(Student.class); student.setStudentid(i); student.setName(dataGenerator.getStudentName(i)); student.setCsci(dataGenerator.getCsciBool(i)); student.setPoints(dataGenerator.getStudentPoints(i)); } realm.commitTransaction(); long timeStop = Debug.threadCpuTimeNanos(); long duration = timeStop - timeStart; values.add(duration); } realm.beginTransaction(); realm.clear(Student.class); realm.commitTransaction(); realm.close(); finalvalues.put(BATCH_WRITE, values); System.gc(); }
public void write() { Log.i("DataStoreBenchmark", "Realm invoking write"); // super.intitalize(); Realm.deleteRealm(realmConfiguration); Realm realm; int i; List<Long> values; long timeStart; values = new ArrayList<>(); realm = Realm.getInstance(realmConfiguration); i = 0; for (int j = 0; j < numberOfIterations; j++) { System.gc(); timeStart = Debug.threadCpuTimeNanos(); realm.beginTransaction(); Student student = realm.createObject(Student.class); student.setStudentid(999); student.setName("Student999"); student.setCsci(true); student.setPoints(100); realm.commitTransaction(); i++; long timeStop = Debug.threadCpuTimeNanos(); long duration = timeStop - timeStart; values.add(duration); } realm.beginTransaction(); realm.clear(Student.class); realm.commitTransaction(); realm.close(); finalvalues.put(SIMPLE_WRITE, values); System.gc(); }
public void simpleQuery() { // super.intitalize(); Realm.deleteRealm(realmConfiguration); Log.i("DataStoreBenchmark", "Realm invoking simple query"); Realm realm; List<Long> values; long timeStart; values = new ArrayList<>(); realm = Realm.getInstance(realmConfiguration); add(realm); check(realm); for (int i = 0; i < numberOfIterations; i++) { System.gc(); timeStart = Debug.threadCpuTimeNanos(); RealmResults<Student> students = realm.where(Student.class).equalTo("csci", false).between("points", 80, 100).findAll(); for (Student student : students) { long tmp = student.getStudentid(); } long timeStop = Debug.threadCpuTimeNanos(); long duration = timeStop - timeStart; values.add(duration); } realm.beginTransaction(); realm.clear(Student.class); realm.commitTransaction(); realm.close(); finalvalues.put(SIMPLE_QUERY, values); System.gc(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).build(); Realm.deleteRealm(realmConfig); // Remember to remove Realm.setDefaultConfiguration(realmConfig); realm = Realm.getInstance(realmConfig); // DO NOT TOUCH!!! if you want realm to work... drawerFragment = (FragmentDrawer) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); drawerFragment.setUp( R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar); drawerFragment.setDrawerListener(this); // display the first navigation drawer view on app launch displayView(0); }
public static void deleteDatabase() { Realm.deleteRealm(configuration); }
public void resetRealm() { RealmConfiguration realmConfig = new RealmConfiguration.Builder(this).deleteRealmIfMigrationNeeded().build(); Realm.deleteRealm(realmConfig); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_realm_basic_example); rootLayout = ((LinearLayout) findViewById(R.id.container)); rootLayout.removeAllViews(); Realm.deleteRealm(new RealmConfiguration.Builder(this).build()); realm = Realm.getInstance(this); // { // long timeMillis = System.currentTimeMillis(); // for (int i = 0; i < 10000; i++) { // BasicContact contact = new BasicContact(); // contact.address = "john" + i + "@example.com"; // contact.number = "#" + i; // contact.active = true; // } // Log.e("IntroExampleActivity", "Create Object Time#: " + // (System.currentTimeMillis() - timeMillis)); // } // { // long timeMillis = System.currentTimeMillis(); // Gson gson = new Gson(); // for (int i = 0; i < 10000; i++) { // BasicContact contact = new BasicContact(); // contact.address = "john" + i + "@example.com"; // contact.number = "#" + i; // contact.active = true; // gson.toJson(contact); // } // Log.e("IntroExampleActivity", "toJson Time#: " + (System.currentTimeMillis() - // timeMillis)); // } // { // long timeMillis = System.currentTimeMillis(); // Gson gson = new Gson(); // for (int i = 0; i < 10000; i++) { // gson.fromJson("{\"address\":\"john" + i + "@example.com\",\"number\":\"#" + i // + "\",\"active\":true}", BasicContact.class); // } // Log.e("IntroExampleActivity", "fromJson Time#: " + (System.currentTimeMillis() - // timeMillis)); // } // { // long timeMillis = System.currentTimeMillis(); // realm.beginTransaction(); // for (int i = 0; i < 10000; i++) { // RealmContact contact = realm.createObject(RealmContact.class); // contact.setAddress("john" + i + "@example.com"); // contact.setNumber("#" + i); // contact.setActive(true); // } // realm.commitTransaction(); // Log.e("IntroExampleActivity", "Realm createObject Time#: " + // (System.currentTimeMillis() - timeMillis)); // } // { // long timeMillis = System.currentTimeMillis(); // realm.beginTransaction(); // for (int i = 0; i < 10000; i++) { // RealmContact contact = new RealmContact(); // contact.setAddress("john" + i + "@example.com"); // contact.setNumber("#" + i); // contact.setActive(true); // realm.copyToRealm(contact); // } // realm.commitTransaction(); // Log.e("IntroExampleActivity", "Realm copyToRealm Time#: " + // (System.currentTimeMillis() - timeMillis)); // } { long timeMillis = System.currentTimeMillis(); realm.beginTransaction(); for (int i = 0; i < 10000; i++) { RealmPrimaryContact contact = new RealmPrimaryContact(); contact.setAddress("john" + i + "@example.com"); contact.setNumber("#" + i); contact.setActive(true); realm.copyToRealmOrUpdate(contact); } realm.commitTransaction(); Log.e( "IntroExampleActivity", "Realm copyToRealmOrUpdate Time#: " + (System.currentTimeMillis() - timeMillis)); } }