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

  • SEARCH
  • Home
  • 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 7403099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:58:11+00:00 2026-05-29T04:58:11+00:00

I have a simple recursive method, a depth first search. On each call, it

  • 0

I have a simple recursive method, a depth first search. On each call, it checks if it’s in a leaf, otherwise it expands the current node and calls itself on the children.

I’m trying to make it parallel, but I notice the following strange (for me) problem.

I measure execution time with System.currentTimeMillis().

When I break the search into a number of subsearches and add the total execution time, I get a bigger number than the sequential search. I only measure execution time, no communication or sync, etc. I would expect to get the same time when I add the times of the subtasks. This happens even if I just run one task after the other, so without threads. If I just break the search into some subtasks and run the subtasks one after the other, I get a bigger time.
If I add the number of method calls for the subtasks, I get the same number as the sequential search. So, basically, in both cases I do the same number of method calls, but I get different times.

I’m guessing there’s some overhead on initial method calls or something else caused by a JVM mechanism. Any ideas what could it be?
For example, one sequential search takes around 3300 ms. If I break it into 13 tasks, it takes a total time of 3500ms.

My method looks like this:

private static final int dfs(State state) {
    method_calls++;
    if(state.isLeaf()){
            return 1;
    }
    State[] children = state.expand();
    int result = 0;
    for (int i = 0; i < children.length; i++) {
            result += dfs(children[i]);
    }
    return result;
}

Whenever I call it, I do it like this:

for(int i = 0; i < num_tasks; i++){
    long start = System.currentTimeMillis();
    dfs(tasks[i]);
    totalTime += (System.currentTimeMillis() - start);
}

Problem is totalTime increases with num_tasks and I would expect to stay the same because the method_calls variable stays the same.

  • 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-29T04:58:14+00:00Added an answer on May 29, 2026 at 4:58 am

    You should average out the numbers over longer runs. Secondly the precision of currentTimeMillis may not be sufficient, you can try using System.nanoTime().

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

Sidebar

Related Questions

I have a rather annoying issue that I solved using a simple recursive method
I have a recursive method call. When any exception is thrown, I would like
I have a simple recursive function RCompare() that calls a more complex function Compare()
I have been experimenting with Lambda expressions in Oxygene. Very simple recursive lambda expression
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple recursive function to write in VBA that does the following
This code involves a recursive Stored Procedure call and a not so great method
I have an Activity that, for each widget in the layout, I call setOnClickListener()
I have a simple recursive algorithm, which returns Fibonacci numbers: private static double fib_recursive(int
I have simple regex \.*\ for me its says select everything between and ,

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.