RosettaCodeData/Task/Time-a-function/E/time-a-function.e

18 lines
485 B
Plaintext

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`)
}