Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:28:31+00:00 2026-05-28T07:28:31+00:00

I am doing some very basic tests to see if using parallel processing in

  • 0

I am doing some very basic tests to see if using parallel processing in my program would provide any noticable speed boost. So far, I’m confused as to the results. In my test, I’m building a tree structure with a branching factor of 30. First, I do my testing using no parallelism, then I try the same thing using a parallel for loop. Here are my results:

Sequential:

Depth: 2 Time: 0.0013964 (900 nodes)
Depth: 3 Time: 0.0053703 (27,000 nodes)
Depth: 4 Time: 0.3994147 (810,000 nodes)
Depth: 5 Time: 14.8306510 (24,300,000 nodes)
Depth: 6 Time: 6:54.4050838 (729,000,000 nodes)

Parallel:

Depth: 2 Time: 0.0389201 (900 nodes)
Depth: 3 Time: 0.1180270 (27,000 nodes)
Depth: 4 Time: 6:06.2296531 (810,000 nodes)

I didn’t bother testing further, as I don’t see it taking less than 7 minutes by the 6 depth.

I have a Dual Core processor, and while I understand that parallelism has a certain amount of overhead, I throught that it wouldn’t be so significant. I have verified that the tree structures genereated in both situations are properly formed to the specified depth with the appropriate number of children (30) at each node.

Here is my code:

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ParallelRecursion
{
    class TreeStructure
    {
        public TreeStructure(int targetLevel, bool runParallel)
        {
            _root = new TreeNode(targetLevel, runParallel);
        }

        private TreeNode _root; 
    }

    class TreeNode
    {
        public TreeNode(int targetLevel, bool runParallel)
        {
            _runParallel = runParallel;

            _rnd = new Random();
            _score = _rnd.Next(int.MinValue, int.MaxValue);

            _level = 0;
            _targetlevel = targetLevel;

            if (_level < _targetlevel)
            {
                if (!_runParallel)
                {
                    _children = new List<TreeNode>();
                    GenerateChildren();
                }
                else
                {
                    _concurrentChildren = new ConcurrentBag<TreeNode>();
                    GenerateParallelChildren();
                }
            }
        }

        public TreeNode(TreeNode treeNode)
        {
            _runParallel = treeNode._runParallel;

            _rnd = treeNode._rnd;
            _score = _rnd.Next(int.MinValue, int.MaxValue);
            _parent = treeNode;

            _level = treeNode._level + 1;
            _targetlevel = treeNode._targetlevel;

            if (_level < _targetlevel)
            {
                if (!_runParallel)
                {
                    _children = new List<TreeNode>();
                    GenerateChildren();
                }
                else
                {
                    _concurrentChildren = new ConcurrentBag<TreeNode>();
                    GenerateParallelChildren();
                }                
            }
        }

        private bool _runParallel;
        private Random _rnd;
        private int _score;
        private int _level;
        private int _targetlevel;
        private TreeNode _parent;
        private List<TreeNode> _children;
        private ConcurrentBag<TreeNode> _concurrentChildren;

        private void GenerateChildren()
        {
            for (int i = 0; i < 30; i++)
            {
                _children.Add(new TreeNode(this));
            }
        }        

        private void GenerateParallelChildren()
        {
            Parallel.For(0, 30, i => { GenerateChild(); });
        }

        private void GenerateChild()
        {
            _concurrentChildren.Add(new TreeNode(this));
        }
    }
}

You can test it using:

TreeStructure ts = new TreeStructure(4, true);//TreeStructure(int targetDepth, bool runParallel)

I’m hoping that I’m doing something wrong. Is it just that this sort of structure isn’t condusive to parallelism?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:28:32+00:00Added an answer on May 28, 2026 at 7:28 am

    The use of ConcurrentBag<T> in one case and List<T> in the other does not make it comparing apples-to-apples. Once you replace List<T> with ConcurrentBag<T> for non-concurrent children, the speed of running both versions becomes more or less the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some processing on some very large video files (often up to 16MP),
I'm at the moment doing some very basic pattern matching with quotations. My code:
I've been doing some very basic SNMP4J programming. All I want to do is
So i have this very basic ipad view controller and i was doing some
while doing some homework in my very strange C++ book, which I've been told
I have very little experience with ASP.NET and I am doing some self-training before
While doing some JavaScript performance tests I came up with the following piece of
While doing some random experimentation with a factorial program in C, Python and Scheme.
While doing some refactoring I've found that I'm quite often using a pair or
I need some suggestions for how to implement a very basic mechanism that logs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.