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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:12+00:00 2026-05-25T11:07:12+00:00

This might be the question that suits to all programming languages(I guess!). I have

  • 0

This might be the question that suits to all programming languages(I guess!). I have a code like this in Groovy:

def a =['asd','sdf','sdr','asd','tty','gfdg','dfgt','rfgsf','rfas','asddre','asdfr','adsrf']
start = System.currentTimeMillis() 
println a.sort()
end = System.currentTimeMillis() 
println "Sort in-built is ${end-start}"
def InsertionSort(def b = [])
{
   for(out=1;out<b.size();out++)
    {
        temp = b[out]
        in1 = out;
        while(in1>0 && b[in1-1]>=temp)
        {
            b[in1] = b[in1-1]
            --in1
        }
        b[in1] = temp;
    }
    return b
}
start = System.currentTimeMillis() 
c = InsertionSort(a)
end = System.currentTimeMillis() 
println "Insertion Sort is ${end-start}"
println c

Clearly the above code checks the running time of in-built sort function and my function named as InsertionSort which also does the same job as sort.

Now I run this same code at different time. Say when I execute the code at time 8:34:33 pm I get the output as:

[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]
Sort in-built is 4
Instertion sort is 6
[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]

Now at 8:35:03 when I execute the same program I get output as:

[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]
Sort in-built is 1
Insertion Sort is 1
[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]

After some moment of seconds I get output as:

[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]
Sort in-built is 0
Insertion Sort is 1
[adsrf, asd, asd, asddre, asdfr, dfgt, gfdg, rfas, rfgsf, sdf, sdr, tty]

Did you notice that the running time of method changes for each execution of the program? Noticeably, the change is vary large from first execution and second execution. So does this mean Groovy caches the latest output somewhere,for some min/sec? How come this change as per second’s?

Thanks in advance.

​

  • 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-25T11:07:12+00:00Added an answer on May 25, 2026 at 11:07 am

    Many reasons.

    1. Other background task taking up CPU time.
    2. In languages using a JVM the JVM could have JIT enabled and optimized certain runs especially if a block of code is repeatedly run without restarting the JVM.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question might have been asked like 100 times, but, believe
This question might be naive as I'm new to ColdFusion programming. I have a
I realize this might be an easy question that I may have overlooked in
This might be an interesting question. I need to test that if I can
This question might not seem programming related at first, but let me explain. I'm
This question might be kind of elementary, but here goes: I have a SQL
I believe this question might have been previously attempted in 2006 on a different
I am afraid that this question might be a little too broad, but I
I know that this might be a duplicate of this question but that was
I realize that this might be a duplicate question but this question is very

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.