Given table t:([c1:1 2]c2:3 4)
I've come across two ways of clearing its content:
t:0#t
delete from `t
Apart from the fact that option (2) returns symbol t
, are there other differences between the two?
Just on that timing test you did you should not re-assign the table if using a number of iterations. After the first iteration you have lost your data so really it only deleted from the table once.
q)n:100000000
q)tbl:([]a:til n;b:n?`3;c:n?1000.0)
q)\ts:3 0N!"Count tbl : ",string count tbl;tbl:0#tbl
"Count tbl : 100000000"
"Count tbl : 0"
"Count tbl : 0"
0 2544
Doing it again with more data and just once shows:
q)n:100000000
q)tbl:([]a:til n;b:n?`3;c:n?1000.0)
q)\ts delete from `tbl
69 268435856
q)tbl:([]a:til n;b:n?`3;c:n?1000.0)
q).Q.gc[]
3489660928
q)\ts tbl:0#tbl
0 944
So looks more efficient to re-assign using :
There is no actual difference in the data returned, however the operations differ in speed slightly.
q)b:([c1:1 2]c2:3 4)
q)\ts:1000000 delete from `b
644 720
q)a:([c1:1 2]c2:3 4)
q)\ts:1000000 a:0#a
195 944
q)b~a
1b