Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
Created November 3, 2022 17:04
Show Gist options
  • Save hiiamboris/bbc22716bf7e9fdb9f661d664b293559 to your computer and use it in GitHub Desktop.
Save hiiamboris/bbc22716bf7e9fdb9f661d664b293559 to your computer and use it in GitHub Desktop.
object size plotter
Red [title: "object size plotter" needs 'view]
sizes: []
plot1: [0x0]
plot2: []
recycle/off
repeat i 70 [
insert spec: [none] to set-word! rejoin ["word" i]
recycle
initial: stats
loop n: 1000 [object spec]
usage: stats - initial / n
append sizes usage
y1: to 1 usage / yscale: 25
y2: to 1 usage / i
repend plot1 [as-pair i * 5 pick last plot1 'y as-pair i * 5 y1]
repend plot2 ['circle as-pair i * 5 y2 3]
]
recycle/on
lines: []
labels1: []
labels2: []
repeat i (400 / f: (1000 / yscale)) - 1 [
repend lines ['move 0x1 * (f * i) 'hline 350]
compose/deep/into [
translate (as-pair 360 f * i + 8) [
matrix [1 0 0 -1 0 0]
text 0x0 (rejoin [i " kB"])
]
] tail labels1
compose/deep/into [
translate (as-pair -40 f * i + 8) [
matrix [1 0 0 -1 0 0]
text 0x0 (rejoin [f * i " b"])
]
] tail labels2
]
lines3: []
labels3: []
repeat i 8 [
i: i - 1
repend lines3 ['move 50x0 * i 'vline 360]
repend labels3 ['text 50x0 * i - 5x0 rejoin [10 * i]]
]
view [
base white 440x440 draw compose/deep [
push [
matrix [1 0 0 -1 45 400]
pen coal shape [(lines) (lines3)]
pen blue fill-pen (sky + 0.0.0.100) shape [line (plot1) 350x0 close]
(labels1)
pen purple fill-pen magenta
(plot2) pen magenta (labels2)
]
pen magenta text 50x10 "bytes per word"
pen blue text 300x10 "kB total"
pen brick translate 45x400 [(labels3)] text 180x420 "number of words"
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment