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 7768675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:58:29+00:00 2026-06-01T15:58:29+00:00

I have a modified version of binary search that takes in an array in

  • 0

I have a modified version of binary search that takes in an array in sorted order and a value, and returns the smallest possible index of an element that is equal to or larger than the given value (or -1 if the value is larger than the max)

Upon the running the above algorithm, everything works fine and the method works as expected. However, I ran it over different input sizes to measure the runtime.

   for(int i=1;i<=20;i++){  
  int size=10*(i*i*i*i);
 int[] array=createRandomSortedArray(size);
 long startTime=System.nanoTime();
 int index=findSmallestIndex(array, needle);
 long et=System.nanoTime()-startTime;
 System.out.println("To find "+needle+" in "+size+" inputs "+" execution time is "+et+" nanoseconds");
}

And following were the observtions:-

To find 50 in 10 inputs  execution time is 5775 nanoseconds
To find 50 in 160 inputs  execution time is 1925 nanoseconds  
To find 50 in 810 inputs  execution time is 4330 nanoseconds
To find 50 in 2560 inputs  execution time is 5293 nanoseconds
To find 50 in 6250 inputs  execution time is 3849 nanoseconds
To find 50 in 12960 inputs  execution time is 3368 nanoseconds
To find 50 in 24010 inputs  execution time is 3849 nanoseconds
To find 50 in 40960 inputs  execution time is 11548 nanoseconds
To find 50 in 65610 inputs  execution time is 9143 nanoseconds
To find 50 in 100000 inputs  execution time is 4812 nanoseconds
To find 50 in 146410 inputs  execution time is 4812 nanoseconds
To find 50 in 207360 inputs  execution time is 11549 nanoseconds  
To find 50 in 285610 inputs  execution time is 8661 nanoseconds
To find 50 in 384160 inputs  execution time is 8661 nanoseconds
To find 50 in 506250 inputs  execution time is 11549 nanoseconds 
To find 50 in 655360 inputs  execution time is 11067 nanoseconds 
To find 50 in 835210 inputs  execution time is 11549 nanoseconds
To find 50 in 1049760 inputs  execution time is 11549 nanoseconds 
To find 50 in 1303210 inputs  execution time is 11067 nanoseconds
To find 50 in 1600000 inputs  execution time is 12030 nanoseconds

I see that execution time for 10 inputs is significantly higher than its successive 160 input size.
To verify things, I ran the execution for 10 inputs by itself outside the loop and following was the result

To find 50 in 10 inputs  execution time is 962 nanoseconds

Why is that so? Why does this anomaly exist? There are couple of other steps too where run time is slower than its preceding lower input size.

  • 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-06-01T15:58:31+00:00Added an answer on June 1, 2026 at 3:58 pm

    Did you let the VM ‘warm up’ prior to running your microbenchmark? Try running this code a few thousand times prior to actually recording any results and see if that makes a difference. You can add the following command line argument to see what gets compiled by the JIT:

    -XX:+PrintCompilation
    

    You can also run your program with

    -Xint
    

    to turn off all Hotspot optimizations and try to get an apples for apples comparison.

    If this isn’t the issue – I suspect there is some constant cost to simply invoking your method. Try increasing the input size linearly and see if you can draw any correlations that way. It’s hard to tell when you jump from 10 to 160.

    Lastly, you might want to include a flag that when enabled will log the behaivor (e.g # of comparisons, etc) the code is performing to see if your doing any unnecessary work.

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

Sidebar

Related Questions

I'm working in a modified version of Sybase 10 that doesn't have the stuff,
We have a custom site written in Perl that uses a slightly modified version
I have a slightly modified version of the thread class copied off the Linux
I have modified a working Windows service that had always been starting beforehand. After
I have a modified version of the jFeed plugin and now want to pack
I have a modified version of PHP which is compiled to PHP, in PHP.
I have the following code, which is a modified version from MSDN's website, to
I have tried. My working copy is based on but a modified version of
I am using a highly modified version of the jqueryFileTree plugin, that is able
I have a javascript function (class) that takes a function reference as one paremter.

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.