\t+

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:ftmr!(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;deasdqdarahm]

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}]

Hi,

I guess asc has an optimization for the case when there are few unique elements. If you try to sort a vector where all elements are unique it will be very slow.

This function seems to be almost as good as asc for the char vector:

fdesc: {{raze(valuei)#'k i:idesc k:key x}count each group x}

WBR, Andrey.

kdb+ uses a hybrid sort which depends on type and distribution.

sort performance improved for certain distributions with v3.5,

and for char vectors in v3.4 2017.02.11.

e.g previously

q)v:0N,-10000000?0

q)\t asc v

9473

and with 3.5

q)\t asc v

2076

thanks