September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
9
Task/Time-a-function/BaCon/time-a-function.bacon
Normal file
9
Task/Time-a-function/BaCon/time-a-function.bacon
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
' Time a function
|
||||
SUB timed()
|
||||
SLEEP 7000
|
||||
END SUB
|
||||
|
||||
st = TIMER
|
||||
timed()
|
||||
et = TIMER
|
||||
PRINT st, ", ", et
|
||||
5
Task/Time-a-function/Halon/time-a-function.halon
Normal file
5
Task/Time-a-function/Halon/time-a-function.halon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$t = uptime();
|
||||
|
||||
sleep(1);
|
||||
|
||||
echo uptime() - $t;
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
import System.CPUTime
|
||||
import System.CPUTime (getCPUTime)
|
||||
|
||||
-- We assume the function we are timing is an IO monad computation
|
||||
timeIt :: (Fractional c) => (a -> IO b) -> a -> IO c
|
||||
timeIt action arg =
|
||||
do startTime <- getCPUTime
|
||||
action arg
|
||||
finishTime <- getCPUTime
|
||||
return $ fromIntegral (finishTime - startTime) / 1000000000000
|
||||
timeIt action arg = do
|
||||
startTime <- getCPUTime
|
||||
action arg
|
||||
finishTime <- getCPUTime
|
||||
return $ fromIntegral (finishTime - startTime) / 1000000000000
|
||||
|
||||
-- Version for use with evaluating regular non-monadic functions
|
||||
timeIt' :: (Fractional c) => (a -> b) -> a -> IO c
|
||||
timeIt' f = timeIt (\x -> f x `seq` return ())
|
||||
timeIt_ :: (Fractional c) => (a -> b) -> a -> IO c
|
||||
timeIt_ f = timeIt ((`seq` return ()) . f)
|
||||
|
|
|
|||
13
Task/Time-a-function/Julia/time-a-function.julia
Normal file
13
Task/Time-a-function/Julia/time-a-function.julia
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# v0.6.0
|
||||
|
||||
function countto(n::Integer)
|
||||
i = zero(n)
|
||||
println("Counting...")
|
||||
while i < n
|
||||
i += 1
|
||||
end
|
||||
println("Done!")
|
||||
end
|
||||
|
||||
@time countto(10 ^ 5)
|
||||
@time countto(10 ^ 10)
|
||||
24
Task/Time-a-function/Kotlin/time-a-function.kotlin
Normal file
24
Task/Time-a-function/Kotlin/time-a-function.kotlin
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// version 1.1.2
|
||||
// need to enable runtime assertions with JVM -ea option
|
||||
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.lang.management.ThreadMXBean
|
||||
|
||||
fun countTo(x: Int) {
|
||||
println("Counting...");
|
||||
(1..x).forEach {}
|
||||
println("Done!")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val counts = intArrayOf(100_000_000, 1_000_000_000)
|
||||
val threadMX = ManagementFactory.getThreadMXBean()
|
||||
assert(threadMX.isCurrentThreadCpuTimeSupported)
|
||||
threadMX.isThreadCpuTimeEnabled = true
|
||||
for (count in counts) {
|
||||
val start = threadMX.currentThreadCpuTime
|
||||
countTo(count)
|
||||
val end = threadMX.currentThreadCpuTime
|
||||
println("Counting to $count takes ${(end-start)/1000000}ms")
|
||||
}
|
||||
}
|
||||
10
Task/Time-a-function/Stata/time-a-function.stata
Normal file
10
Task/Time-a-function/Stata/time-a-function.stata
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
program timer_test
|
||||
timer clear 1
|
||||
timer on 1
|
||||
sleep `0'
|
||||
timer off 1
|
||||
timer list 1
|
||||
end
|
||||
|
||||
. timer_test 1000
|
||||
1: 1.01 / 1 = 1.0140
|
||||
1
Task/Time-a-function/Zkl/time-a-function.zkl
Normal file
1
Task/Time-a-function/Zkl/time-a-function.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
t:=Time.Clock.time; Atomic.sleep(3); (Time.Clock.time - t).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue