File Exchange

image thumbnail

cmp: a pedestrian yet very fast file comparator

version (3.1 KB) by us
CMP compares two files byte by byte

1 Download

Updated 11 Apr 2007

View License

CMP compares two files byte by byte employing a speed and memory optimized engine.
if the files do not match, CMP prints/returns the position and the numerical and ASCII character representation of the first differing byte and its ten neighbors.


% create a file with 80 megabytes of random data
clear tmat;

% wintel systems:
% 1) p5/1.6ghz/512mb/win2k/r2007a
% > elapsed time = 3.7021 seconds
% 2) p5/2.6ghz/512mb/winxp/r2007a
% > elapsed time = 2.1013 seconds
% 3) c2.2*2.4ghz/2gb/winvista/r2007a
% > elapsed time = 1.0190 seconds

> help cmp
and the screen shot for more information about this self-explanatory snippet and its few options.

Cite As

us (2020). cmp: a pedestrian yet very fast file comparator (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)


I was tested this programs application on several computer platforms with different operation systems[]. Program documantation and code-write-style is not-regular although this submission don't merit comments as poor review.

Good works, Best Regards

[]: MSI-K9Neo-Platinium, AMD-Athlon 64bit 3GHZ,2000-Fsb,1GB Dual-Ram,Non-overclok,
Elapsed time : 1.023452 second (Microsoft-Windows-Xp(Sp2)
Elapsed time : 1.053245 second (Suse-linux 9.0)

John D'Errico

Whoever this "x y" is, this individual has improperly singled out a worthy contribution to the FEX. CMP has excellent help, an H1 line, carefully written modular code, error checks, it is speedy and works on any system. Urs has, as always, provided a well crafted code.

I'd add only one line to the help. I tested the code out on an m-file on my search path. This failed, so at first I assumed this code did not run on m-files. This seemed wrong, so I looked deeper, to realize that the file names must include the full path if they do not lie in the current directory. While this is indeed an eminently logical behavior, the help for cmp states only that the file name must include any extensions. An alternative would be to add a call to which if a file does not appear in the directory listing.

urs (us) schwarz

dear reviewer, you are correct: i took the liberty to remove previous versions of this snippet because of uncommented ratings, which eventually spiraled into a ridiculous star-war.
THIS TIME you took the time to comment on your rating - i really do not care about the stars - as long as they are based on some thoughts.
In addition, i will cherish this review all the more as it puts me on the same level as some of our true ML role models like john (d'errico, i assume), duane (hanselman), and jos (van der geest).

x y

Why does this submission keep appearing, then disappearing? At least this time it is not called "pedestrian". When will you elitists, Us, John, Duane, Jos, etc. stop being so harsh in criticizing submissions just because they are created by nonprofessionals?

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!