functions ta(@) and td(.) compare the times of functions run on given value(s)
the functions also check that the result matches a given result (in `m).
the result is also returned in `r.
a test shows an interesting time difference between asc and desc for ascii letters [(reverse asc) mag faster than desc]
$ q t.q
KDB+ 3.4 2016.06.14 Copyright (C) 1993-2016 Kx Systems
l32/ 4()core 6936MB jack g50 127.0.1.1 NONEXPIRE
“run with function”
f | t m r ..
--------------------------| -------------------------------------------------..
{asc x} | 6 0 `s#"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..
{reverse asc x} | 8 1 "~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
{desc asc x} | 78 1 "~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
{x[0],desc 1_x} | 141 0 "i~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
{desc x} | 145 1 "~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
{desc x} | 147 1 "~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
{desc (neg count x)?asc x}| 169 1 "~zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..
$ cat t.q
t:{[r;v;f]e:(enlist n),(n:16?" “),/:“fv”;($e)set'(n;f;v);t:<wbr>system "t
“,n,” set .[”,(“;“sv 1_e),”]”;r:f
tm
r!(f;t;r~R;R:value n);(`$e)set’(::);r}
td:{{$[98=type x;asc 1!x;x]}t[x;y]@'z} /td . f has many args
ta:{td[x;enlist y;z]} /ta @ f takes one arg
de:{desc x}
as:{asc x}
dq:{desc (neg count x)?asc x}
da:{desc asc x}
ra:{reverse asc x}
hm:{x[0],desc 1_x}
r:desc x:(300100?" “),”~"
0N!“run with function”; show ta[r;x;de,de,as,dq,da,ra,hm]
/
0N!“run with name”; show ta[r;x;de
asdq
dara
hm]
0N!“one shot dot”; show td[r;(100;x);{dq x#y}]
0N!“two shot dot”; show td[r;(100;x);{dq y},{dq x#y}]