2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -2,6 +2,7 @@
{{omit from|GUISS}}
{{omit from|ML/I}}
;Task:
Write a program which uses a timer (with the least granularity available
on your system) to time how long a function takes to execute.
@ -11,3 +12,4 @@ between start and finish, which could include time used by
other processes on the computer.
This task is intended as a subtask for [[Measure relative performance of sorting algorithms implementations]].
<br><br>

View file

@ -0,0 +1,22 @@
@echo off
Setlocal EnableDelayedExpansion
call :clock
::timed function:fibonacci series.....................................
set /a a=0 ,b=1,c=1
:loop
if %c% lss 2000000000 echo %c% & set /a c=a+b,a=b, b=c & goto loop
::....................................................................
call :clock
echo Function executed in %timed% hundredths of second
goto:eof
:clock
if not defined timed set timed=0
for /F "tokens=1-4 delims=:.," %%a in ("%time%") do (
set /A timed = "(((1%%a - 100) * 60 + (1%%b - 100)) * 60 + (1%%c - 100)) * 100 + (1%%d - 100)- %timed%"
)
goto:eof

View file

@ -2,24 +2,30 @@ package main
import (
"fmt"
"time"
"testing"
)
func from(t0 time.Time) {
fmt.Println(time.Now().Sub(t0))
}
func empty() {
defer from(time.Now())
}
func empty() {}
func count() {
defer from(time.Now())
for i := 0; i < 1e6; i++ {
}
}
func main() {
empty()
count()
e := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
empty()
}
})
c := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
count()
}
})
fmt.Println("Empty function: ", e)
fmt.Println("Count to a million:", c)
fmt.Println()
fmt.Printf("Empty: %12.4f\n", float64(e.T.Nanoseconds())/float64(e.N))
fmt.Printf("Count: %12.4f\n", float64(c.T.Nanoseconds())/float64(c.N))
}

View file

@ -0,0 +1,25 @@
package main
import (
"fmt"
"time"
)
func from(t0 time.Time) {
fmt.Println(time.Now().Sub(t0))
}
func empty() {
defer from(time.Now())
}
func count() {
defer from(time.Now())
for i := 0; i < 1e6; i++ {
}
}
func main() {
empty()
count()
}

View file

@ -1,2 +1,4 @@
(6!:2,7!:2) '|: 50 50 50 $ i. 50^3'
0.00387912 1.57414e6
(6!:2 , 7!:2) '|: 50 50 50 $ i. 50^3'
0.00488008 3.14829e6
timespacex '|: 50 50 50 $ i. 50^3'
0.00388519 3.14829e6

View file

@ -0,0 +1 @@
CodeTools:-Usage(ifactor(32!+1), output = realtime, quiet);

View file

@ -0,0 +1 @@
CodeTools:-Usage(ifactor(32!+1), output = cputime, quiet);

View file

@ -1,4 +1,4 @@
time(foo)={
foo();
gettime()
};
gettime();
}

View file

@ -0,0 +1,5 @@
time(foo)={
my(start=getabstime());
foo();
getabstime()-start;
}

View file

@ -1,31 +1,27 @@
/*REXX program to show the elapsed time for a function (or subroutine). */
arg times . /*get the arg from command line. */
if times=='' then times=100000 /*any specified? No, use default*/
/*REXX program displays the elapsed time for a REXX function (or subroutine). */
arg reps . /*obtain an optional argument from C.L.*/
if reps=='' then reps=100000 /*Not specified? No, then use default.*/
call time 'Reset' /*only the 1st character is examined. */
junk = silly(reps) /*invoke the SILLY function (below). */
/*───► CALL SILLY REPS also works.*/
call time 'R' /*only 1st character is examined.*/
call time 'reset' /*this verbose version also works*/
call time 'rompishness' /*and yet another example. */
junk = silly(times) /*invoke the SILLY function. */
/* CALL SILLY TIMES also works.*/
/*The E is for elapsed time.*/
/**/
/* ┌────────┘ */
/**/
/**/
say 'function SILLY took' format(time("E"),,2) 'seconds for' times "iterations."
/**/
/**/
/* ┌────────────────┘ */
/**/
/* The above 2 for the FORMAT function displays the time */
/* with 2 decimal digits (past the decimal point). Using */
/* a 0 (zero) would round the time to whole seconds. */
exit
/*──────────────────────────────────SILLY subroutine────────────────────*/
silly: procedure /*chew up some CPU time doing some silly stuff.*/
do j=1 for arg(1) /*wash, apply, lather, rinse, repeat. ... */
a.j=random() date() time() digits() fuzz() form() xrange() queued()
end /*j*/
return j-1
/* The E is for elapsed time.*/
/* │ ─ */
/* ┌────◄───┘ */
/**/
/**/
say 'function SILLY took' format(time("E"),,2) 'seconds for' reps "iterations."
/**/
/**/
/* ┌────────►───────┘ */
/**/
/* The above 2 for the FORMAT function displays the time with*/
/* two decimal digits (rounded) past the decimal point). Using */
/* a 0 (zero) would round the time to whole seconds. */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
silly: procedure /*chew up some CPU time doing some silly stuff.*/
do j=1 for arg(1) /*wash, apply, lather, rinse, repeat. ··· */
@.j=random() date() time() digits() fuzz() form() xrange() queued()
end /*j*/
return j-1

View file

@ -1,26 +1,27 @@
/*REXX program shows the CPU time used for a REXX pgm since it started. */
arg times . /*get the arg from command line. */
if times=='' then times=100000 /*any specified? No, use default*/
junk = silly(times) /*invoke the SILLY function. */
/* CALL SILLY TIMES also works.*/
/*REXX program displays the elapsed time for a REXX function (or subroutine). */
arg reps . /*obtain an optional argument from C.L.*/
if reps=='' then reps=100000 /*Not specified? No, then use default.*/
call time 'Reset' /*only the 1st character is examined. */
junk = silly(reps) /*invoke the SILLY function (below). */
/*───► CALL SILLY REPS also works.*/
/*The J is for time used by */
/* │ the REXX program */
/* ┌────────┘ since it started, */
/*this is a Regina extension. */
/**/
say 'function SILLY took' format(time("J"),,2) 'seconds for' times "iterations."
/**/
/**/
/* ┌────────────────┘ */
/**/
/* The above 2 for the FORMAT function displays the time */
/* with 2 decimal digits (past the decimal point). Using */
/* a 0 (zero) would round the time to whole seconds. */
exit
/*──────────────────────────────────SILLY subroutine────────────────────*/
silly: procedure /*chew up some CPU time doing some silly stuff.*/
do j=1 for arg(1) /*wash, apply, lather, rinse, repeat. ... */
a.j=random() date() time() digits() fuzz() form() xrange() queued()
end /*j*/
return j-1
/* The J is for the CPU time used */
/* │ by the REXX program since */
/* ┌───────┘ since the time was RESET. */
/* This is a Regina extension.*/
/* */
say 'function SILLY took' format(time("J"),,2) 'seconds for' reps "iterations."
/* */
/* */
/* ┌────────►───────┘ */
/* */
/* The above 2 for the FORMAT function displays the time with*/
/* two decimal digits (rounded) past the decimal point). Using */
/* a 0 (zero) would round the time to whole seconds. */
exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
silly: procedure /*chew up some CPU time doing some silly stuff.*/
do j=1 for arg(1) /*wash, apply, lather, rinse, repeat. ··· */
@.j=random() date() time() digits() fuzz() form() xrange() queued()
end /*j*/
return j-1