Skip to content

Instantly share code, notes, and snippets.

@MrStonedOne MrStonedOne/_output.txt
Last active Sep 23, 2018

Embed
What would you like to do?
Memory usage stats of different collections in BYOND
Sample Size = 500000
Starting Usage = 39.09mb
List of lists, before fill: 42.96mb Diff:3.87mb Each:8.12b
List of lists, after fill: 61.04mb Diff:18.08mb - 37.92b
List of datums, before fill: 64.87mb Diff:3.82mb Each:8.02b
List of datums, after fill: 83.14mb Diff:18.27mb Each:38.32b
List of strings, before fill: 86.96mb Diff:3.82mb Each:8.01b
List of strings, after fill: 162.11mb Diff:75.14mb Each:157.59b
List of strings, preloaded string tree, before fill: 165.93mb Diff:3.83mb Each:8.03b
List of strings, preloaded string tree, after fill: 165.94mb Diff:4kb Each:0.01b
Previous list with numbers assoicated with each value (assoicated usage): 184.61mb Diff:18.68mb Each:39.17b
/*
These are simple defaults for your project.
*/
world
loop_checks = FALSE
/proc/getmem()
return text2num(call("bmem.dll", "mem")()) //get from https://github.com/vuonojenmustaturska/tgstation/tree/rustsysinfo/tools/bmem-dll/Release
#define SAMPLE_SIZE 500000
/client/verb/memorytest()
var/startingmemory = getmem()
var/list/lists = new (SAMPLE_SIZE)
var/listemptymemory = getmem()
for (var/i in 1 to SAMPLE_SIZE)
lists[i] = list()
var/listfullmemory = getmem()
var/list/datums = new (SAMPLE_SIZE)
var/datumemptymemory = getmem()
for (var/i in 1 to SAMPLE_SIZE)
datums[i] = new /datum()
var/datumfullmemory = getmem()
var/list/slists = new (SAMPLE_SIZE)
var/slistemptymemory = getmem()
for (var/i in 1 to SAMPLE_SIZE)
slists[i] = num2text(rand(1,(2**24))*rand(), 99)
var/slistfullmemory = getmem()
var/list/pslists = new (SAMPLE_SIZE)
var/pslistemptymemory = getmem()
for (var/i in 1 to SAMPLE_SIZE)
pslists[i] = slists[i]
var/pslistfullmemory = getmem()
for (var/i in 1 to SAMPLE_SIZE)
pslists[pslists[i]] = rand(1,(2**24))*rand()
var/salistfullmemory = getmem()
world << "Sample Size = [SAMPLE_SIZE]"
world << "Starting Usage = [standardizesize(startingmemory)]"
world << "List of lists, before fill: [standardizesize(listemptymemory)] Diff:[standardizesize(listemptymemory - startingmemory)] Each:[standardizesize((listemptymemory - startingmemory)/SAMPLE_SIZE)]"
world << "List of lists, after fill: [standardizesize(listfullmemory)] Diff:[standardizesize(listfullmemory - listemptymemory)] - [standardizesize((listfullmemory - listemptymemory)/SAMPLE_SIZE)]"
world << "List of datums, before fill: [standardizesize(datumemptymemory)] Diff:[standardizesize(datumemptymemory - listfullmemory)] Each:[standardizesize((datumemptymemory - listfullmemory)/SAMPLE_SIZE)]"
world << "List of datums, after fill: [standardizesize(datumfullmemory)] Diff:[standardizesize(datumfullmemory - datumemptymemory)] Each:[standardizesize((datumfullmemory - datumemptymemory)/SAMPLE_SIZE)]"
world << "List of strings, before fill: [standardizesize(slistemptymemory)] Diff:[standardizesize(slistemptymemory - datumfullmemory)] Each:[standardizesize((slistemptymemory - datumfullmemory)/SAMPLE_SIZE)]"
world << "List of strings, after fill: [standardizesize(slistfullmemory)] Diff:[standardizesize(slistfullmemory - slistemptymemory)] Each:[standardizesize((slistfullmemory - slistemptymemory)/SAMPLE_SIZE)]"
world << "List of strings, preloaded string tree, before fill: [standardizesize(pslistemptymemory)] Diff:[standardizesize(pslistemptymemory - slistfullmemory)] Each:[standardizesize((pslistemptymemory - slistfullmemory)/SAMPLE_SIZE)]"
world << "List of strings, preloaded string tree, after fill: [standardizesize(pslistfullmemory)] Diff:[standardizesize(pslistfullmemory - pslistemptymemory)] Each:[standardizesize((pslistfullmemory - pslistemptymemory)/SAMPLE_SIZE)]"
world << "Previous list with numbers assoicated with each value (assoicated usage): [standardizesize(salistfullmemory)] Diff:[standardizesize(salistfullmemory - pslistfullmemory)] Each:[standardizesize((salistfullmemory - pslistfullmemory)/SAMPLE_SIZE)]"
/proc/standardizesize(size)
var/append = "b"
if (size > 2048)
append = "kb"
size /= 1024
if (size > 2048)
append = "mb"
size /= 1024
if (size > 2048)
append = "gb"
size /= 1024
return "[round(size, 0.01)][append]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.