Rate counter: Difference between revisions
Content added Content deleted
(Add BaCon) |
(Added Kotlin) |
||
Line 785: | Line 785: | ||
return times; |
return times; |
||
}</lang> |
}</lang> |
||
=={{header|Kotlin}}== |
|||
{{trans|JavaScript}} |
|||
<lang scala>// version 1.1.3 |
|||
typealias Func<T> = (T) -> T |
|||
fun cube(n: Int) = n * n * n |
|||
fun <T> benchmark(n: Int, func: Func<T>, arg: T): LongArray { |
|||
val times = LongArray(n) |
|||
for (i in 0 until n) { |
|||
val m = System.nanoTime() |
|||
func(arg) |
|||
times[i] = System.nanoTime() - m |
|||
} |
|||
return times |
|||
} |
|||
fun main(args: Array<String>) { |
|||
println("\nTimings (nanoseconds) : ") |
|||
for (time in benchmark(10, ::cube, 5)) println(time) |
|||
}</lang> |
|||
Sample output: |
|||
<pre> |
|||
154430 |
|||
2100 |
|||
1275 |
|||
1138 |
|||
1063 |
|||
1113 |
|||
1087 |
|||
1088 |
|||
1063 |
|||
1025 |
|||
</pre> |
|||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |