Created
October 24, 2016 09:16
-
-
Save sliskiCode/c37655de9d39a22c19031760e37d7d0a to your computer and use it in GitHub Desktop.
Builders in Kotlin. Gist 4
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
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