Created
August 23, 2021 07:24
-
-
Save kota1921/fd79a85d08dda6f998414d48a8b4acbc to your computer and use it in GitHub Desktop.
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
@RunWith(AndroidJUnit4::class) | |
class KotlinSerializationBenchmark { | |
private val context = ApplicationProvider.getApplicationContext<Context>() | |
private val simpleJsonString = Utils.readJsonAsStringFromDisk(context, R.raw.simple) | |
@get:Rule val benchmarkRule = BenchmarkRule() | |
@Before | |
fun init() { | |
val field = androidx.benchmark.BenchmarkState::class.java.getDeclaredField("REPEAT_COUNT") | |
field.isAccessible = true | |
field.set(benchmarkRule, Utils.GLOBAL_REPEAT_COUNT) | |
} | |
@Test | |
fun testRead() { | |
benchmarkRule.measureRepeated { | |
Json.decodeFromString<List<SmallObject>>(simpleJsonString ?: "") | |
} | |
} | |
@Test | |
fun testWrite() { | |
val testObjects = Json.decodeFromString<List<SmallObject>>(simpleJsonString ?: "") | |
benchmarkRule.measureRepeated { | |
Json.encodeToString(testObjects) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment