September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,9 @@
' Time a function
SUB timed()
SLEEP 7000
END SUB
st = TIMER
timed()
et = TIMER
PRINT st, ", ", et

View file

@ -0,0 +1,5 @@
$t = uptime();
sleep(1);
echo uptime() - $t;

View file

@ -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)

View 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)

View 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")
}
}

View 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

View file

@ -0,0 +1 @@
t:=Time.Clock.time; Atomic.sleep(3); (Time.Clock.time - t).println();