Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Last active January 24, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhunzaker/2a1d9a5a64312aaf1a4c to your computer and use it in GitHub Desktop.
Save nhunzaker/2a1d9a5a64312aaf1a4c to your computer and use it in GitHub Desktop.
Instructions
●° rollup this-inside-out.js | node --expose-gc
Running 10 trials at 1000 records each:
Generated 1000 records
Growth: 2.74%
Generated 1000 records
Growth: -8.73%
Generated 1000 records
Growth: -0.08%
Generated 1000 records
Growth: 0.24%
Generated 1000 records
Growth: 0.07%
Generated 1000 records
Growth: 0.06%
Generated 1000 records
Growth: 0.07%
Generated 1000 records
Growth: 0.07%
Generated 1000 records
Growth: 0.07%
Generated 1000 records
Growth: 0.07%
Average memory growth for all 10 samples: -0.54%
import User, { create } from './user'
var size = 10
var depth = 1000
var total = 0
console.log('Running %s trials at %s records each:\n', size, depth)
function test (depth) {
var context = {}
while (depth--) {
create(context, { first_name : 'Sally', last_name : 'Smith' })
}
console.log('Generated %s records', User.size(context))
}
for (var i = 0; i < size; i++) {
global.gc()
var memoryBefore = process.memoryUsage().heapUsed
test(depth)
global.gc()
var memoryAfter = process.memoryUsage().heapUsed
var growth = ((memoryAfter - memoryBefore) / memoryBefore) * 100
console.log('Growth: %s%\n', growth.toFixed(2))
total += growth
}
console.log("Average memory growth for all %s samples: %s%", size, (total / size).toFixed(2))
const DB = new WeakMap()
export function create (context, record) {
var next = new Set(DB.get(context))
next.add(record)
DB.set(context, next)
return record
}
export default {
size(context) {
return DB.has(context) ? DB.get(context).size : 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment