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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:30:47+00:00 2026-06-04T01:30:47+00:00

I have a multithreaded mergesorting program in C, and a program for benchmark testing

  • 0

I have a multithreaded mergesorting program in C, and a program for benchmark testing it with 0, 1, 2, or 4 threads. I also wrote a program in Python to do multiple tests and aggregate the results.

The weird thing is that when I run the Python, the tests always run in about half the time compared to when I run them directly in the shell.

For example, when I run the testing program by itself with 4 million integers to sort (the last two arguments are the seed and modulus for generating integers):

$ ./mergetest 4000000 4194819 140810581084
0 threads:  1.483485s wall;  1.476092s user;  0.004001s sys
1 threads:  1.489206s wall;  1.488093s user;  0.000000s sys
2 threads:  0.854119s wall;  1.608100s user;  0.008000s sys
4 threads:  0.673286s wall;  2.224139s user;  0.024002s sys

Using the python script:

$ ./mergedata.py 1 4000000
Average runtime for 1 runs with 4000000 items each:
0 threads:   0.677512s wall;   0.664041s user;   0.016001s sys
1 threads:   0.709118s wall;   0.704044s user;   0.004001s sys
2 threads:   0.414058s wall;   0.752047s user;   0.028001s sys
4 threads:   0.373708s wall;    1.24008s user;   0.024002s sys

This happens no matter how many I’m sorting, or how many times I run it. The python program calls the tester with the subprocess module, then parses and aggregates the output. Any ideas why this would happen? Is Python somehow optimizing the execution? or is there something slowing it down when I run it directly that I’m not aware of?

Code: https://gist.github.com/2650009

  • 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-04T01:30:48+00:00Added an answer on June 4, 2026 at 1:30 am

    Turns out I was passing sys.maxint to the subprocess as the modulus for generating random numbers. C was truncating the 64-bit integer and interpreting it as signed, i.e., -1 in two’s complement, so every random number was being mod’d by that and becoming 0. So, sorting all the same values seems to take about half as much time as random data.

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

Sidebar

Related Questions

I have a multithreaded openCV program that uses 4 threads to do the following:
Situation: I have a multithreaded program written in C. If one of the threads
I have to code a multithreaded(say 2 threads) program where each of these threads
I have a long-running multithreaded program, and I'd like to occasionally like to call
I have a speed critical multithreaded program which involves data in a tree structure.
I have a multithreaded Windows application where one of the threads has a message
I have a multithreaded program where I create a generator function and then pass
I have a multithreaded app that uses sqlite. When two threads try to update
I have a multithreaded Java code in which: several threads read stateful objects from
Say I have a multithreaded application made up of two separate threads and a

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.