| 104 | measure("WeakSet (empty)", () => new WeakSet); |
| 105 | |
| 106 | function measure(name, what) |
| 107 | { |
| 108 | let slots, chunks, result; |
| 109 | |
| 110 | Debug.gc(); |
| 111 | |
| 112 | slots = Instrumentation.get(xsInstrumentation.slot_used); |
| 113 | chunks = Instrumentation.get(xsInstrumentation.chunk_used); |
| 114 | |
| 115 | result = what(); // holding result so it isn't collected before measuring |
| 116 | |
| 117 | Debug.gc(); |
| 118 | |
| 119 | slots = Instrumentation.get(xsInstrumentation.slot_used) - slots; |
| 120 | chunks = Instrumentation.get(xsInstrumentation.chunk_used) - chunks; |
| 121 | |
| 122 | if (slots && chunks) |
| 123 | trace(`${name}: ${slots / slotSize} slots + ${chunks} chunk bytes = ${slots + chunks} bytes\n`); |
| 124 | else if (slots) |
| 125 | trace(`${name}: ${slots / slotSize} slots = ${slots + chunks} bytes\n`); |
| 126 | else if (chunks) |
| 127 | trace(`${name}: ${chunks} chunk bytes = ${slots + chunks} bytes\n`); |
| 128 | else |
| 129 | trace(`${name}: 0 bytes\n`); |
| 130 | |
| 131 | return result; |
| 132 | } |
| 133 | |
| 134 | function empty() {} |