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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:26:19+00:00 2026-06-10T16:26:19+00:00

I wanted to try combining use of memcmp with multithreading there’s this code that

  • 0

I wanted to try combining use of memcmp with multithreading

there’s this code that benchmarked seems to be fastest I’ve had so far ..but I wanted to check if I could further accelerate the comparison process .

thoughts I had :

1) via multithreading it.

2) another idea,

is it possible in the case of byte[]
to check if it’s 80% to 100% same (if it’s possible at all..)
giving this option will it reduce the time of computation?

the first question is in higher priority…if i must choose..

    public static bool ByteArrayCompare(byte[] b1, byte[] b2)
    {
        return b1.Length == b2.Length && memcmp(b1, b2, b1.Length) == 0;
    }
  • 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-10T16:26:21+00:00Added an answer on June 10, 2026 at 4:26 pm

    You might get to speed it up by multithreading. Simply launch multiple N threads each thread will compare the 1/N of your array. HOWEVER, this only makes sense on the multicore machine. Also keep in mind that spawning new threads and collecting their results will put a fixed time penalty on your operation, which might in fact be greater than just doing it on a single thread. Another thing to consider, is that your code will be as slow as the slowest thread, so if you spawn to many threads you would have to wait until your last thread complete.

    You might get extra clever and consider more devious scheme, when you can detect that one of the threads has found that the data is not the same. This thread then can signal to the master thread about it and you can safely terminate the rest of the running threads early.

    The actual speedup depends on how large the data you are comparing ( I am assuming it is pretty large since you are considering this ). And how often that data is the same or all different. If your data is different often enough you will get considerable speedup.

    As for your second idea. Yes you can come up with the scheme that will get your faster you can either randomly sample both arrays and once you find at least one byte that is different you can declare both datasets to be different and terminate early. However again you should be careful how you implement this. First you should sample compare in blocks not just individual bytes. Look into your HW architecture cache / prefetch behavior to determine the optimal block size. Also, if you know something about you data you should try to sample the areas that are more likely to be different first. You might get better results, by not doing the random sampling, but by sampling at predictable pattern. So that if you fail to find the difference using random sampling, you can just compare the rest of your data without re-comparing the data you already processed.

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

Sidebar

Related Questions

I just wanted to try out this code... #include <iostream> #include <stdio.h> #include <string.h>
I wanted to try to allocate a 4 billion bytes array and this is
I found this link and I wanted to try the carousel example out. I
I wanted to try out this example of a self-hosted webservice (originally written in
I was just reading this question and wanted to try the alias method rather
I wanted to make a ViewController that had some text editing functionality I wanted
I wanted to try out TBB's scalable_allocator, but was confused when I had to
I really wanted to try to figure out how to use a Category or
I wanted to try open Hello World from here . I already had Visual
i wanted to try the following code: //all arrays are List<T> type. if (m.terms[0]

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.