RosettaCodeData/Task/Time-a-function/E/time-a-function.e
2023-07-01 13:44:08 -04:00

17 lines
485 B
Text

def countTo(x) {
println("Counting...")
for _ in 1..x {}
println("Done!")
}
def MX := <unsafe:java.lang.management.makeManagementFactory>
def threadMX := MX.getThreadMXBean()
require(threadMX.isCurrentThreadCpuTimeSupported())
threadMX.setThreadCpuTimeEnabled(true)
for count in [10000, 100000] {
def start := threadMX.getCurrentThreadCpuTime()
countTo(count)
def finish := threadMX.getCurrentThreadCpuTime()
println(`Counting to $count takes ${(finish-start)//1000000}ms`)
}