Skip to content

Instantly share code, notes, and snippets.

@rianoc
Created April 18, 2021 08:06
Show Gist options
  • Save rianoc/195e66b5be840c170f36be26804020a7 to your computer and use it in GitHub Desktop.
Save rianoc/195e66b5be840c170f36be26804020a7 to your computer and use it in GitHub Desktop.
Kdb+ bytes to KB,MB,GB,TB
`syms _.Q.w[]
used| 10407392
heap| 67108864
peak| 67108864
wmax| 0
mmap| 0
mphy| 8464715776
symw| 1380256

Step dictionary to convert

convertB:`s#(!). flip (
(1                ;{.Q.f[2;x],"B"});
(1024             ;{.Q.f[2;x%1024],"KB"});
(`long$1024 xexp 2;{.Q.f[2;x%1024 xexp 2],"MB"});
(`long$1024 xexp 3;{.Q.f[2;x%1024 xexp 3],"GB"});
(`long$1024 xexp 4;{.Q.f[2;x%1024 xexp 4],"TB"})
);
dashH:{convertB[x]@'x}
dashH `syms _.Q.w[]
used| "9.93MB"
heap| "64.00MB"
peak| "64.00MB"
wmax| "0.00B"
mmap| "0.00B"
mphy| "7.88GB"
symw| "1.32MB"

Also possible using bin

dashH:{("B";"KB";"MB";"GB";"TB")[i]{y,x}'.Q.f[2] each x%l i:(l:1 1024,`long$1024 xexp 2 3 4) bin x}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment