Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
50
Task/Time-a-function/AWK/time-a-function.awk
Normal file
50
Task/Time-a-function/AWK/time-a-function.awk
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# syntax: GAWK -f TIME_A_FUNCTION.AWK [-v delay=x] [<NUL}
|
||||
# examples:
|
||||
# GAWK -f TIME_A_FUNCTION.AWK
|
||||
# GAWK -f TIME_A_FUNCTION.AWK -v delay=1
|
||||
# GAWK -f TIME_A_FUNCTION.AWK -v delay=1.0 <NUL
|
||||
@load "time"
|
||||
BEGIN {
|
||||
delay += 0
|
||||
printf("delay=%s\n",delay)
|
||||
#
|
||||
start = systime()
|
||||
do_something()
|
||||
stop = systime()
|
||||
show("accurate to one second using GAWK's builtin systime()")
|
||||
#
|
||||
start = dos_time()
|
||||
do_something()
|
||||
stop = dos_time()
|
||||
show("accurate to 1/100th of a second using Windows TIME command ")
|
||||
#
|
||||
start = gettimeofday()
|
||||
do_something()
|
||||
stop = gettimeofday()
|
||||
show("accurate to 1/1000000th of a second using GAWK's time extension")
|
||||
#
|
||||
exit(0)
|
||||
}
|
||||
function dos_time( cmd,seconds,x) { # Windows time in HH:MM:SS.hh format
|
||||
# assumes 24 hour clock
|
||||
cmd = "TIME <NUL"
|
||||
cmd | getline x # The current time is: 12:34:56.78
|
||||
close(cmd)
|
||||
seconds = substr(x,22,2) * 3600 # hour
|
||||
seconds += substr(x,25,2) * 60 # minute
|
||||
seconds += substr(x,28,2) # second
|
||||
seconds += substr(x,31,2) / 100 # hundred second
|
||||
return(seconds)
|
||||
}
|
||||
function do_something() {
|
||||
sleep(delay)
|
||||
print("press ENTER to continue")
|
||||
getline
|
||||
}
|
||||
function show(msg) {
|
||||
if (start > stop) {
|
||||
print("next day rollover occurred")
|
||||
}
|
||||
printf("%.6f seconds (%017.6f-%017.6f)\n",stop-start,stop,start)
|
||||
printf("%s\n\n",msg)
|
||||
}
|
||||
31
Task/Time-a-function/Ada/time-a-function.adb
Normal file
31
Task/Time-a-function/Ada/time-a-function.adb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
with Ada.Calendar; use Ada.Calendar;
|
||||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
|
||||
procedure Query_Performance is
|
||||
type Proc_Access is access procedure(X : in out Integer);
|
||||
function Time_It(Action : Proc_Access; Arg : Integer) return Duration is
|
||||
Start_Time : Time := Clock;
|
||||
Finis_Time : Time;
|
||||
Func_Arg : Integer := Arg;
|
||||
begin
|
||||
Action(Func_Arg);
|
||||
Finis_Time := Clock;
|
||||
return Finis_Time - Start_Time;
|
||||
end Time_It;
|
||||
procedure Identity(X : in out Integer) is
|
||||
begin
|
||||
X := X;
|
||||
end Identity;
|
||||
procedure Sum (Num : in out Integer) is
|
||||
begin
|
||||
for I in 1..1000 loop
|
||||
Num := Num + I;
|
||||
end loop;
|
||||
end Sum;
|
||||
Id_Access : Proc_Access := Identity'access;
|
||||
Sum_Access : Proc_Access := Sum'access;
|
||||
|
||||
begin
|
||||
Put_Line("Identity(4) takes" & Duration'Image(Time_It(Id_Access, 4)) & " seconds.");
|
||||
Put_Line("Sum(4) takes:" & Duration'Image(Time_It(Sum_Access, 4)) & " seconds.");
|
||||
end Query_Performance;
|
||||
10
Task/Time-a-function/ArkScript/time-a-function.ark
Normal file
10
Task/Time-a-function/ArkScript/time-a-function.ark
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(import std.Sys)
|
||||
|
||||
(let work (fun (x) (sys:sleep (random x (* 2 x)))))
|
||||
|
||||
(let timer (fun (f) {
|
||||
(let start (time))
|
||||
(f)
|
||||
(- (time) start) }))
|
||||
|
||||
(print (timer (fun () (work 50))))
|
||||
5
Task/Time-a-function/Euphoria/time-a-function.eu
Normal file
5
Task/Time-a-function/Euphoria/time-a-function.eu
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
atom t
|
||||
t = time()
|
||||
some_procedure()
|
||||
t = time() - t
|
||||
printf(1,"Elapsed %f seconds.\n",t)
|
||||
12
Task/Time-a-function/PowerShell/time-a-function.ps1
Normal file
12
Task/Time-a-function/PowerShell/time-a-function.ps1
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function fun($n){
|
||||
$res = 0
|
||||
if($n -gt 0) {
|
||||
1..$n | foreach{
|
||||
$a, $b = $_, ($n+$_)
|
||||
$res += $a + $b
|
||||
}
|
||||
|
||||
}
|
||||
$res
|
||||
}
|
||||
"$((Measure-Command {fun 10000}).TotalSeconds) Seconds"
|
||||
Loading…
Add table
Add a link
Reference in a new issue