Created
March 22, 2016 09:41
-
-
Save beeender/5da3c7c1b150e8a89176 to your computer and use it in GitHub Desktop.
String conversion benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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