Droid vs Nexus 1: Who can calculate MD5 faster?

Nexus 1 indeed.


17 files get their MD5 calculated on the Droid


and 17 files get their MD5 hash calculated on the Nexus 1

Nexus 1 pwns.

Here’s the code in case you’re curious.
[java]
public void onClick(View v) {
_logTextView.setText("MD5 Benchmark on " + Build.DEVICE + "nn");
if (GlobalVariables.APP_CONTEXT == null)
GlobalVariables.APP_CONTEXT = getApplicationContext();

List<FileDescriptor> sharedAudioFiles = Engine.INSTANCE.LIBRARIAN.getSharedAudioFiles(0, 17);
for (FileDescriptor fs: sharedAudioFiles) {
long start = 0;
String md5 = null;
long length = 0;
try {
start = System.currentTimeMillis();
File f = new File(fs.path);
length = f.length();
md5 = FrostWireUtils.getMD5(f);

} catch (Exception e) { }
long time = System.currentTimeMillis() – start;
_logTextView.append(FrostWireUtils.getBytesInHuman(length) + " in " + time + " ms @ " + (length/(double) time)*1000 + " b/sn");
}
}
[/java]

And here’s how we do the MD5
[java]
public final static String getMD5(File f) throws Exception {
MessageDigest m = MessageDigest.getInstance("MD5");

byte[] buf = new byte[65536];
int num_read;

InputStream in = new BufferedInputStream(new FileInputStream(f));

while ((num_read = in.read(buf)) != -1) {
m.update(buf, 0, num_read);
}

String result = new BigInteger(1, m.digest()).toString(16);

// pad with zeros if until it’s 32 chars long.
if (result.length() < 32) {
StringBuffer padding = new StringBuffer();
int paddingSize = 32 – result.length();
for (int i = 0; i < paddingSize; i++)
padding.append("0");

result = padding.toString() + result;
}

return result;
}
[/java]

Safari 3.1 Benchmark part II – VS Firefox 3.0b4

This is the Part II of Benchmarks between Safari 3.1’s JavaScript engine and Firefox. Last Benchmark was done against Firefox 2, and Safari destroyed Firefox’s Javascript engine, in some aspects being up to 7 times faster.

So I was curious and I downloaded and tried the benchmark on Firefox 3.0b4. to see how much Firefox 3.0 will improve its Javascript performance, key to today’s web applications and the future of the web.

After seeing the results, I say Kudos to the Firefox 3 team, they’ve improved considerably their JavaScript engine and that only makes me glad cause I won’t have to switch to Safari. 🙂

I will not make any tests on HTML rendering, if you find any benchmark results on HTML rendering, please leave links on the comments section.

Once again, here are the results side by side:

FIREFOX 3.0b4
========================
RESULTS 
(means and 95% confidence intervals)
-----------------------------------------
Total:                 3876.6ms +/- 0.9%
-----------------------------------------

  3d:                   489.0ms +/- 1.3%
    cube:               193.8ms +/- 1.2%
    morph:              138.2ms +/- 1.5%
    raytrace:           157.0ms +/- 3.8%

  access:               594.2ms +/- 5.6%
    binary-trees:        57.4ms +/- 5.9%
    fannkuch:           246.0ms +/- 0.8%
    nbody:              219.8ms +/- 13.6%
    nsieve:              71.0ms +/- 2.1%

  bitops:               470.4ms +/- 0.7%
    3bit-bits-in-byte:   67.8ms +/- 1.5%
    bits-in-byte:        90.8ms +/- 1.8%
    bitwise-and:        177.4ms +/- 1.1%
    nsieve-bits:        134.4ms +/- 0.5%

  controlflow:           42.4ms +/- 1.6%
    recursive:           42.4ms +/- 1.6%

  crypto:               257.2ms +/- 1.2%
    aes:                 87.4ms +/- 1.3%
    md5:                 83.8ms +/- 4.0%
    sha1:                86.0ms +/- 0.0%

  date:                 412.0ms +/- 0.4%
    format-tofte:       251.6ms +/- 0.6%
    format-xparb:       160.4ms +/- 0.4%

  math:                 502.0ms +/- 2.2%
    cordic:             188.0ms +/- 0.5%
    partial-sums:       231.2ms +/- 5.2%
    spectral-norm:       82.8ms +/- 3.6%

  regexp:               275.6ms +/- 1.0%
    dna:                275.6ms +/- 1.0%

  string:               833.8ms +/- 0.7%
    base64:              98.6ms +/- 1.4%
    fasta:              228.8ms +/- 3.2%
    tagcloud:           166.2ms +/- 0.6%
    unpack-code:        218.6ms +/- 0.5%
    validate-input:     121.6ms +/- 0.6%
SAFARI 3.1
========================
RESULTS 
(means and 95% confidence intervals)
-----------------------------------------
Total:                 3368.8ms +/- 1.0%
-----------------------------------------

  3d:                   414.8ms +/- 1.9%
    cube:               132.2ms +/- 2.4%
    morph:              144.6ms +/- 4.1%
    raytrace:           138.0ms +/- 0.6%

  access:               520.4ms +/- 4.1%
    binary-trees:        78.6ms +/- 11.3%
    fannkuch:           231.4ms +/- 2.0%
    nbody:              149.2ms +/- 8.1%
    nsieve:              61.2ms +/- 3.9%

  bitops:               449.6ms +/- 2.4%
    3bit-bits-in-byte:   69.8ms +/- 9.6%
    bits-in-byte:        99.2ms +/- 4.6%
    bitwise-and:        167.2ms +/- 2.3%
    nsieve-bits:        113.4ms +/- 6.7%

  controlflow:           91.2ms +/- 4.7%
    recursive:           91.2ms +/- 4.7%

  crypto:               247.2ms +/- 2.3%
    aes:                 81.2ms +/- 2.5%
    md5:                 83.8ms +/- 4.6%
    sha1:                82.2ms +/- 2.0%

  date:                 306.4ms +/- 0.5%
    format-tofte:       146.6ms +/- 1.4%
    format-xparb:       159.8ms +/- 1.0%

  math:                 454.8ms +/- 1.3%
    cordic:             174.4ms +/- 1.6%
    partial-sums:       193.8ms +/- 1.2%
    spectral-norm:       86.6ms +/- 4.4%

  regexp:               209.6ms +/- 0.7%
    dna:                209.6ms +/- 0.7%

  string:               674.8ms +/- 2.2%
    base64:             103.8ms +/- 9.0%
    fasta:              177.0ms +/- 1.0%
    tagcloud:           136.0ms +/- 4.6%
    unpack-code:        136.0ms +/- 1.7%
    validate-input:     122.0ms +/- 2.6%

Almost there. Only in Flow control and recursion it beats Safari, the rest needs to improve, however, it’s improved a lot comparing to the previous version of Firefox.

The machine used for this test is a MacBook Pro running Mac OS X Version 10.4.11 with a 2.33 GHz Intel Core 2 Duo and 2GB 667 MHz DDR2 SDRAM.

New Safari’s JavaScript engine Kicks Ass!

So I downloaded yesterday the latest Software Update for Mac OSX and it included an update of the Safari Web Browser, which I had taken for dead ages ago, I’m a hardcore Firefox user.

Today I read about the new updates, and I read something that caught my eye at Mackinando.com.

it executes JavaScript six times faster than the rest

I go to the Safari Site, and they compare themselves with a previous version, Firefox, and Opera (not IE, not even worth mentioning)

I couldn’t believe my eyes, so I googled for “JavaScript Benchmark“, and tried the SunSpider JavaScript Benchmark onboth Firefox 2.0.0.12 and the shiny new Safari 3.1.

The machine used for this test is a MacBook Pro running Mac OS X Version 10.4.11 with a 2.33 GHz Intel Core 2 Duo and 2GB 667 MHz DDR2 SDRAM.

Here are the results side by side:

FIREFOX 2.0.0.12
========================
RESULTS 
(means and 95% confidence intervals)
-----------------------------------------
Total:                 15365.4ms +/- 1.7%
-----------------------------------------

  3d:                   2386.6ms +/- 7.9%
    cube:                733.0ms +/- 20.8%
    morph:              1269.8ms +/- 9.4%
    raytrace:            383.8ms +/- 37.1%

  access:               1386.2ms +/- 4.8%
    binary-trees:        201.6ms +/- 0.6%
    fannkuch:            294.8ms +/- 5.4%
    nbody:               691.2ms +/- 8.9%
    nsieve:              198.6ms +/- 1.5%

  bitops:               3461.2ms +/- 0.4%
    3bit-bits-in-byte:   275.8ms +/- 0.6%
    bits-in-byte:        248.2ms +/- 0.7%
    bitwise-and:        2765.2ms +/- 0.5%
    nsieve-bits:         172.0ms +/- 4.7%

  controlflow:           153.4ms +/- 0.7%
    recursive:           153.4ms +/- 0.7%

  crypto:                527.2ms +/- 0.5%
    aes:                 230.8ms +/- 1.2%
    md5:                 147.4ms +/- 0.5%
    sha1:                149.0ms +/- 0.6%

  date:                 2551.8ms +/- 0.3%
    format-tofte:       1449.6ms +/- 0.3%
    format-xparb:       1102.2ms +/- 0.8%

  math:                 1312.6ms +/- 12.8%
    cordic:              497.4ms +/- 12.0%
    partial-sums:        501.6ms +/- 1.6%
    spectral-norm:       313.6ms +/- 36.1%

  regexp:                501.0ms +/- 0.2%
    dna:                 501.0ms +/- 0.2%

  string:               3085.4ms +/- 10.3%
    base64:              914.6ms +/- 3.4%
    fasta:               676.0ms +/- 35.4%
    tagcloud:            441.4ms +/- 0.6%
    unpack-code:         846.8ms +/- 25.4%
    validate-input:      206.6ms +/- 1.1%
SAFARI 3.1
========================
RESULTS 
(means and 95% confidence intervals)
-----------------------------------------
Total:                 3368.8ms +/- 1.0%
-----------------------------------------

  3d:                   414.8ms +/- 1.9%
    cube:               132.2ms +/- 2.4%
    morph:              144.6ms +/- 4.1%
    raytrace:           138.0ms +/- 0.6%

  access:               520.4ms +/- 4.1%
    binary-trees:        78.6ms +/- 11.3%
    fannkuch:           231.4ms +/- 2.0%
    nbody:              149.2ms +/- 8.1%
    nsieve:              61.2ms +/- 3.9%

  bitops:               449.6ms +/- 2.4%
    3bit-bits-in-byte:   69.8ms +/- 9.6%
    bits-in-byte:        99.2ms +/- 4.6%
    bitwise-and:        167.2ms +/- 2.3%
    nsieve-bits:        113.4ms +/- 6.7%

  controlflow:           91.2ms +/- 4.7%
    recursive:           91.2ms +/- 4.7%

  crypto:               247.2ms +/- 2.3%
    aes:                 81.2ms +/- 2.5%
    md5:                 83.8ms +/- 4.6%
    sha1:                82.2ms +/- 2.0%

  date:                 306.4ms +/- 0.5%
    format-tofte:       146.6ms +/- 1.4%
    format-xparb:       159.8ms +/- 1.0%

  math:                 454.8ms +/- 1.3%
    cordic:             174.4ms +/- 1.6%
    partial-sums:       193.8ms +/- 1.2%
    spectral-norm:       86.6ms +/- 4.4%

  regexp:               209.6ms +/- 0.7%
    dna:                209.6ms +/- 0.7%

  string:               674.8ms +/- 2.2%
    base64:             103.8ms +/- 9.0%
    fasta:              177.0ms +/- 1.0%
    tagcloud:           136.0ms +/- 4.6%
    unpack-code:        136.0ms +/- 1.7%
    validate-input:     122.0ms +/- 2.6%

Comparing with Firefox, the overall result of this test was that it’s 4.56 times faster.

However, if we look test by test, there are areas where I feel embarrassed for Firefox.

Bitwise Operations
For example, Bit-Operation tests in Safari 3.1 are 7.7 times faster in Safari, being the case of the bitwise-AND (&) operator the worst of them, Safari performed bitwise-and’s 16 times faster than Firefox

OUCH!!

String Operations
So you’d be curious now about String operations, which is probably a lot of what goes on with Javascript, and Ajax, parsing those XML results and what not, maybe the bitwise & won’t hurt us that much given that not many programmers today are smart enough to use them for web programming.

When it comes to String operations, Safari 3.1 was 4.5 times faster than Firefox 2.

Kudos to the Safari Team, I thought there was no point in having Safari until I did this benchmark. I guess they don’t want to let go of Web Browser users, maybe they make millions every month with ad-clicks on Google generated with the search field they have at the top of the browser which is set by default to do Google search.

Once again the saying proves it self

“Competition is good”

Let’s hope this will make the Firefox team think more on Javascript improvements with the upcoming Firefox 3. Once it’s release ready, it’ll be worth it running this benchmark again and see where it stands.

Update (March 20th, 2008)

I’ve made tests on Firefox 3 beta 4, You can see the results here. Tests have been made again on the same Macbook Pro. The improvements of Firefox 3 are notable, however, on the mac, Safari still wins.