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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:12:32+00:00 2026-05-30T13:12:32+00:00

I have a function that compares two files to see if they are the

  • 0

I have a function that compares two files to see if they are the same. It reads the files byte by byte and checks to see they are the same.
The problem I’m having now is that for big files this function takes quite a long time.

What is the better, faster way to check if files are the same?

  • 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-30T13:12:34+00:00Added an answer on May 30, 2026 at 1:12 pm

    When your files are not the same, are they likely to be of the same size? If not, you can determine the file sizes right away (fseek to the end, ftell to determine the position), and if they’re different then you know they’re not the same without comparing the data. If the size is the same, remember to fseek back to the beginning.

    If you read your files into large buffers of memory and compare each buffer using memcmp() you will improve performance. You don’t have to read the entire file at once, just set a large buffer size and read blocks of that size from each file, for each comparison iteration through your loop. The memcpy function will operate on 32 bit values, rather than 8 bit bytes.

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

Sidebar

Related Questions

I have written a function that checks if to files are duplicates or not.
So, the idea was a write a recursive function that compares two strings to
I am trying to write an operator != function that compares if two complex
I have a function that should be passed a string with two numbers (as
I would like help finishing my function that compares two arrays and returns the
I have been trying to make a script that compares two images in HTML5
I have a function that takes in two strings, and I want to, let's
I need to do operations like compare that two number arrays have the same
I have two arrays of JavaScript Objects that I'd like to compare to see
I have two dictionaries of data and I created a function that acts as

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.