I have a shared library in c that calls q with k(). I notice that k() is relatively expensive.
Is there any way to make it faster? Thanks!
: air:q ; cat b.c
// derived from http://kx.com/q/c/c/a.c
// clang -Wall -Wextra -m32 -bundle -undefined dynamic_lookup -L./m32 b.c -o m32/b.so
#include <stdio.h>
#include"k.h"
K f(K x){return ki(x->i+1);} // q calls c
K g(K x){return k(0,“1+”,r1(x),0);} // c calls q
K h(K x){return k(0,“fq”,r1(x),0);} // ditto; fq:{:1+x} in b.q
: air:q ; cat b.q
f:b 2:(
f;1)
g:b 2:(
g;1)
fq:{:1+x}
h:b 2:(
h;1)
M:1000*1000
\ts do[M; f 0]
\ts do[M; ff:f 0]
\ts do[M; g 0]
\ts do[M; gg:g 0]
\ts do[M; h 0]
\ts do[M; hh:h 0]
\
: air:q ; q b.q
KDB+ 2.8 2012.09.02 Copyright (C) 1993-2012 Kx Systems
m32/ 2()core 4096MB hjh air.local 10.0.1.2 PLAY 2012.12.01
404 592j
661 704j
5810 592j / c calling q is not cheap
5019 704j
5194 592j
6442 704j
: air:q ;