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,18 @@
' Rate counter
FOR i = 1 TO 3
GOSUB timeit
NEXT
i = 2000
GOSUB timeit
END
LABEL timeit
iter = 0
starter = TIMER
WHILE TRUE DO
INCR iter
IF TIMER >= starter + i THEN BREAK
WEND
PRINT iter, " iterations in ", i, " millisecond", IIF$(i > 1, "s", "")
RETURN

View file

@ -0,0 +1,4 @@
DO I = FIRST,LAST
IF (PROGRESSNOTE((I - FIRST)/(LAST - FIRST + 1.0))) WRITE (6,*) "Reached ",I,", towards ",LAST
...much computation...
END DO

View file

@ -0,0 +1,20 @@
// 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)
}

View file

@ -0,0 +1,29 @@
# Project : Rate counter
# Date : 2017/09/11
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
see "method 1: calculate reciprocal of elapsed time:" + nl
for trial = 1 to 3
start = clock()
tasktomeasure()
finish = clock()
see "rate = " + 100 / (finish-start) + " per second" + nl
next
see "method 2: count completed tasks in one second:" + nl
for trial = 1 to 3
runs = 0
finish = clock() + 100
while clock() < finish
tasktomeasure()
if clock() < finish
runs = runs + 1
ok
end
see "rate = " + runs + " per second" + nl
next
func tasktomeasure
for i = 1 to 100000
next

View file

@ -0,0 +1,18 @@
fcn rateCounter(f,timeNRuns,secsToRun=Void){
now:=Time.Clock.time;
if(secsToRun){
then:=now + secsToRun;
N:=0; do{ f(); N+=1; }while(Time.Clock.time<then);
t:=Time.Clock.time - now;
println("%d runs in %s seconds = %.3f sec/run"
.fmt(N,Time.Date.toHMSString(0,0,t),t.toFloat()/N));
}
else{
do(timeNRuns){ f() }
t:=Time.Clock.time - now;
println("%s seconds to run %d times = %.3f sec/run"
.fmt(Time.Date.toHMSString(0,0,t),timeNRuns,
t.toFloat()/timeNRuns));
t
}
}

View file

@ -0,0 +1,3 @@
ns:=List.createLong(0d100_000,(0).random,True); // one hundred thousand ints
rateCounter('wrap(){ ns.copy().sort() },20);
rateCounter('wrap(){ ns.copy().sort() },Void,10);