Last active
August 30, 2018 12:19
-
-
Save pflannery/11bfe55a14dd54c768f7 to your computer and use it in GitHub Desktop.
Comparing heaps for TaskGroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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