Script Preparation code:
x
 
function *dfs(root) {
    yield root;
    for (let child of root.children) {
        yield *dfs(child);
    }
}
function *bfsArray(root) {
    let queue = [root];
    do {
        let node = queue.shift();
        yield node;
        queue.push(...node.children);
    } while (queue.length);
}
function *bfsLinkedList(root) {
    let head = {node: root, next: null};
    let tail = head;
    do {
        let node = head.node;
        yield node;
        for (let child of node.children) {
            tail = tail.next = {node: child, next: null};
        }
        head = head.next;
    } while (head !== null);
}
function makeRandomTree(depth, degree) {
    let node = {
        data: Math.round(Math.random() * 100),
        children: []
    };
    if (depth !== 0)
    for (let i = 0; i < degree; ++i) {
        node.children.push(makeRandomTree(depth - 1, degree));
    }
    return node;
}
const testTree = makeRandomTree(7, 5);
Tests:
  • Pre-order

     
    for (let node of dfs(testTree)) {node.data;}
  • Level-order with array

     
    for (let node of bfsArray(testTree)) {node.data;}
  • Level-order with linked list

     
    for (let node of bfsLinkedList(testTree)) {node.data;}
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Pre-order
    Level-order with array
    Level-order with linked list

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Firefox 138 on Windows
View result in a separate tab
Test name Executions per second
Pre-order 20.6 Ops/sec
Level-order with array 100.6 Ops/sec
Level-order with linked list 104.8 Ops/sec