Skip to content

Instantly share code, notes, and snippets.

@beeender
Created March 22, 2016 09:41
Show Gist options
  • Save beeender/5da3c7c1b150e8a89176 to your computer and use it in GitHub Desktop.
Save beeender/5da3c7c1b150e8a89176 to your computer and use it in GitHub Desktop.
String conversion benchmark
@Test
public void setString_Benchmark() {
final int TEST_COUNT = 100000;
String[] strings = new String[TEST_COUNT];
for (int i = 0; i < TEST_COUNT; i++) {
strings[i] = UUID.randomUUID().toString();
}
realm.beginTransaction();
long startTime = System.nanoTime();
for (int i = 0; i < TEST_COUNT; i++) {
Dog dog = realm.createObject(Dog.class);
dog.setName(strings[i]);
realm.copyToRealm(dog);
}
long endTime = System.nanoTime();
realm.commitTransaction();
long time = (endTime - startTime)/1000/1000;
Log.e("TTT", "Setting " + TEST_COUNT + " strings takes " + time + "ms. Avg time for one string is " +
time/TEST_COUNT + "ms");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment