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.

	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");
				}
			}

And here’s how we do the MD5

	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;
	}
Did this help you? Tip $1 Tip $2 Tip $5

One Response to “Droid vs Nexus 1: Who can calculate MD5 faster?”

  1. gubatron Says:

    test

Leave a Reply