Here is my code
fun main() {
val list1 = listOf("channel_name", "timestamp_us", "column_3", "column_4", "channel_name", "timestamp_us", "column_3", "column_4")
val start = System.nanoTime()
list1.joinToString(prefix = "(", postfix = ")")
val end = System.nanoTime()
print(end - start)}
And the output is much more than 1,000,000.Usually it's about 8,000,000. However,if I change my code to this:
fun main() {
val list1 = listOf("channel_name", "timestamp_us", "column_3", "column_4", "channel_name", "timestamp_us", "column_3", "column_4")
val list2 = listOf("channel_name", "timestamp_us", "column_3", "column_4", "channel_name", "timestamp_us", "column_3", "column_4")
list1.joinToString()
val start = System.nanoTime()
list2.joinToString(prefix = "(", postfix = ")")
val end = System.nanoTime()
print(end - start)}
The output usually is 15,000.
So, can anyone explain why the output of the first code is 600 times that of the second code?
My computer is MacBook Pro (16-inch, 2019),
jdk is jdk1.8.0_251,
code run in IntelliJ IDEA 2020.2.2 (Community Edition)
Kotlin plugin version is 1.4.10