Skip to content

Instantly share code, notes, and snippets.

@pflannery
Last active August 30, 2018 12:19
Show Gist options
  • Save pflannery/11bfe55a14dd54c768f7 to your computer and use it in GitHub Desktop.
Save pflannery/11bfe55a14dd54c768f7 to your computer and use it in GitHub Desktop.
Comparing heaps for TaskGroup
'use strict'
let TaskGroup = require('./taskgroup')
let util = require('./util')
let mode = 'heap'
let testname = 'taskgroup-profile-test'
// Start profiling
if ( mode === 'profile' ) util.startProfile(testname)
// Prepare
let createTask = function(name, value){
return function() {
// $status.innerHTML += value
return value
}
}
// Create the taskgroup
let tasks = TaskGroup.create()
util.saveSnapshot("started")
// Add the tasks
for ( let i = 0, n = 50000; i < n; ++i ) {
let name = 'Task '+i
let value = 'Value '+i
let task = createTask(name, value)
tasks.addTask(name, task)
}
// Listen for complete
tasks.done(function(){
if ( mode === 'heap') {
util.saveSnapshot("completed")
} else {
setTimeout(function(){
util.stopProfile(testname)
}, 2000)
}
})
// Run the tasks
tasks.run()
util.saveSnapshot("afterRun")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment