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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:14:33+00:00 2026-06-14T01:14:33+00:00

I’m writing some program with sorting algorithms comparsion using Python. I want to measure

  • 0

I’m writing some program with sorting algorithms comparsion using Python. I want to measure average sorting time. I have a problem with first measurement.

This:

for i in xrange(self.repeats):
    # random list generator
    data_orig = [random.randint(0, self.size - 1) for x in xrange(self.size)]

    sorter = self.class_()
    data = data_orig[:]
    debug("%s for data size: %d, try #%d" % (sorter.__class__.__name__, self.size, i+1))
    t1 = time.clock()
    sorter.sort(data)
    t2 = time.clock()
    debug("Took: %0.4fms, shifts: %d, comparisons: %d" % ((t2-t1)*1000.0, sorter.shifts, sorter.comps))

class_ is a reference to InsertionSort class.
For size = 1000 and 5 repeats I get following results:

InsertionSort for data size: 1000, try #1
Took: 39.5341ms, shifts: 254340, comparisons: 255331
InsertionSort for data size: 1000, try #2
Took: 6.0765ms, shifts: 250778, comparisons: 251772
InsertionSort for data size: 1000, try #3
Took: 6.9946ms, shifts: 254189, comparisons: 255180
InsertionSort for data size: 1000, try #4
Took: 6.7421ms, shifts: 252162, comparisons: 253156
InsertionSort for data size: 1000, try #5
Took: 5.9584ms, shifts: 241412, comparisons: 242404

For every sorting algorithm and every time I run program first result is bigger than the others. I run it with PyPy (with Python it seems OK, but it’s MUCH slower).

I know I can simply ommit first results but this solution doesn’t satisfies me 🙂

Any ideas?

  • 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-14T01:14:35+00:00Added an answer on June 14, 2026 at 1:14 am

    Because that’s the whole point of PyPy. It’s an optimizing just-in-time compiler, which means that the more you run a piece of code, the more optimized it gets. The first time you run it, it hasn’t had a chance to do any optimization, so the result will be slow. Subsequent runs will take into account the lessons learned from the first time, so will be faster.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have been unable to fix a problem with Java Unicode and encoding. The
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.