Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Created October 24, 2016 09:16
Show Gist options
  • Save sliskiCode/c37655de9d39a22c19031760e37d7d0a to your computer and use it in GitHub Desktop.
Save sliskiCode/c37655de9d39a22c19031760e37d7d0a to your computer and use it in GitHub Desktop.
Builders in Kotlin. Gist 4
fun main(args: Array<String>) {
measureTime {
Person.create {
name { "Peter" }
surname { "Slesarew" }
age { 28 }
}
}
// OR
measureTime {
Person.create {
name = "Peter"
surname = "Slesarew"
age = 28
}
}
}
inline fun measureTime(func: () -> Unit) {
(1..100).forEach {
val start = System.nanoTime()
(1..1000).forEach {
func()
}
println("Time: ${System.nanoTime() - start}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment