/ Generate data for the contract_item table, inventorybig and inventorysmall$ / Then generate numtests test sales. / These are updates for inventorybig / These are selects followed by updates for inventorysmall if present / and they are selects followed by inserts when they are not. / Replication testing: / Generate some string data types. / Updates & Inserts. / All relevant parameters can be found under PARAM / BASIC ROUTINES / find difference between list[0] and list[1] listdiff:{[list] :differ[list[0]; list[1]] } / returns one if x is a subset of y subset:{[x; y] i: y ?/: x : ~ (#y) _in i } / returns one if x is a subset of y subset:{[x;y] (#y) > |/ y ?/: x} differ:{[x;y] x,: () y,: () i: y ?/: x j: & i = #y :?x[j] } / A faster difference, yielding indexes in x that differ from y differindexes:{[x;y] i: y ?/: x j: & i = #y :j } /finds intersection of two lists / fastest of all intersect: {[x;y] x,: () y,: () i: x ?/: y :x[(?i) _dv #x] } /finds intersection of two lists / fastest of all intersect: {[x;y] x,: () y,: () if[(#x) < (#y) i: x ?/: y j: & i < #x :x[?i[j]] ] i: y ?/: x j: & i < #y :y[?i[j]] } /finds intersection of two lists / fastest of all hasintersect: {[x;y] x,: () y,: () i: x ?/: y : (&/i) < #x } / x is a proper subset of y propersubset:{[x;y] x,: () y,: () if[~ (#x) < (#y); :0] / must be smaller :(#x) = (#intersect[x;y]) } / x is a proper subset of y propersubset:{[x;y] x,: () y,: () if[~ (#x) < (#y); :0] / must be smaller :subset[x;y] } /finds indexes in x and y that intersect / If x and y are both sets, then the results will be of the same length / fastest of all intersectindexes: {[x;y] i: x ?/: y / where each y hits j: & i < #x / those ys that hit :(i[j];j) } /finds indexes in x that intersect with y intersectleftindexes: {[x;y] i: x ?/: y / where each y hits j: & i < #x / those ys that hit :i[j] } /finds intersection of two lists / and returns index pairs of matches. Assumes no duplicates / in either list intersectbothindexes: {[x;y] x,: () y,: () i: x ?/: y pairs: (i ,' (!#y)) k: & pairs[;0] < #x :pairs[k] } / finds intersection of two lists that may have duplicates bagintersectbothindexes:{[x;y] alreadyused: out: () i: 0 while[i < #x my: x[i] jj: & y ~\: my jj: differ[jj; alreadyused] if[0 < #jj out,: ,(i;*jj) alreadyused,: *jj ] i+: 1 ] :out } / intersect many lists multiintersect:{[lists] size: #lists if[2 > size; :lists] first: lists[0],() jj: ,/ ?:' first (?/:)/: lists[1+ !(size-1)] / find indexes in first x: @[(1+#first) # 0; jj; + ; 1] x: (-1) _ x / delete missing entry kk: & x = size - 1 :first[kk] } / this is a set intersection so we remove duplicates multiintersect:{[lists] size: #lists if[2 > size; :lists] first: lists[0],() jj: first ?/: (,/ ?:' lists[1+ !(size-1)]) / find indexes in first x: @[(1+#first) # 0; jj; + ; 1] x: (-1) _ x / delete missing entry kk: & x = size - 1 :first[kk] } avg:{(+/ x) % # x} var:{avg[_sqr x] - _sqr avg[x]} std:{_sqrt var[x]} cov:{avg[x * y] - avg[x] * avg[y]} corr:{ (cov[x;y])%((std[x]) * (std[y]))} / delay based search corrdelay:{[delay;x;y] x: (-delay) _ x y: delay _ y (cov[x;y])%((std[x]) * (std[y]))} / END BASICS / APPLICATION SPECIFIC spitvert:{[list] ,/ ($list) ,\: ("|")} spitcomma:{[list] x: (-1) _ ,/ ($list) ,\: (",") :x,(")")} spitcommaexec:{[list] x: (-1) _ ,/ ($list) ,\: (",") :x,(");")} / PARAMETERS numtests: 10000 if[0 < #_i numtests: 0 $ _i[0] ] ` 0: ,"k reptest numtests" / EXECUTION vowels: "AEIOU " consonants: "ABCDEFGHIJKLMNOPQRSTUVWXYZTTSS" lets: vowels, consonants, vowels outsmall: () outlargefixed: () outlargevar: () outmixed: () i: 0 while[i < numtests x1: lets[10 _draw #lets] x2: lets[100 _draw #lets] x3: lets[230 _draw #lets] outsmall,: ,("insert into smallfixedstring values(\""), x1, ("\")") outlargefixed,: ,("insert into largefixedstring values(\""), x2, ("\")") outlargevar,: ,("insert into largevar values(\""), x3, ("\")") outmixed,: ,("insert into mixedstrings values(\""), x1, ("\",\""), x2, ("\",\""), x3, ("\")") i+: 1 ] "tmprepsmall" 0: outsmall "tmpreplargefixed" 0: outlargefixed "tmpreplargevar" 0: outlargevar "tmprepmixed" 0: outmixed