bench: simple working benchmark

This commit is contained in:
Vincent Breitmoser
2015-11-04 20:24:06 +01:00
parent 8feed0b097
commit a4518c43c2
8 changed files with 52 additions and 20 deletions

View File

@@ -27,6 +27,7 @@ import android.support.annotation.NonNull;
import org.sufficientlysecure.keychain.operations.results.BenchmarkResult;
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
@@ -54,9 +55,10 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
public BenchmarkResult execute(BenchmarkInputParcel consolidateInputParcel,
CryptoInputParcel cryptoInputParcel) {
OperationLog log = new OperationLog();
log.add(LogType.MSG_BENCH, 0);
// random data
byte[] buf = new byte[1024];
byte[] buf = new byte[1024*1024*5];
new Random().nextBytes(buf);
Passphrase passphrase = new Passphrase("a");
@@ -66,24 +68,30 @@ public class BenchmarkOperation extends BaseOperation<BenchmarkInputParcel> {
{
SignEncryptOperation op =
new SignEncryptOperation(mContext, mProviderHelper,
new ProgressScaler(mProgressable, 0, 10, 100), mCancelled);
new ProgressScaler(mProgressable, 0, 50, 100), mCancelled);
SignEncryptParcel input = new SignEncryptParcel();
input.setSymmetricPassphrase(passphrase);
input.setBytes(buf);
encryptResult = op.execute(input, new CryptoInputParcel());
}
log.add(encryptResult, 1);
log.add(LogType.MSG_BENCH_ENC_TIME, 1,
String.format("%.2f", encryptResult.getResults().get(0).mOperationTime / 1000.0));
// decrypt
DecryptVerifyResult decryptResult;
{
PgpDecryptVerifyOperation op =
new PgpDecryptVerifyOperation(mContext, mProviderHelper,
new ProgressScaler(mProgressable, 0, 10, 100));
new ProgressScaler(mProgressable, 50, 100, 100));
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes());
input.setAllowSymmetricDecryption(true);
decryptResult = op.execute(input, new CryptoInputParcel(passphrase));
}
log.add(decryptResult, 1);
log.add(LogType.MSG_BENCH_DEC_TIME, 1, String.format("%.2f", decryptResult.mOperationTime / 1000.0));
log.add(LogType.MSG_BENCH_SUCCESS, 0);
return new BenchmarkResult(BenchmarkResult.RESULT_OK, log);
}

View File

@@ -39,7 +39,7 @@ public class DecryptVerifyResult extends InputPendingResult {
byte[] mOutputBytes;
public long mTotalTime;
public long mOperationTime;
public DecryptVerifyResult(int result, OperationLog log) {
super(result, log);

View File

@@ -874,6 +874,12 @@ public abstract class OperationResult implements Parcelable {
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
MSG_LV_FETCH_ERROR_FORMAT(LogLevel.ERROR, R.string.msg_lv_fetch_error_format),
MSG_LV_FETCH_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_lv_fetch_error_nothing),
MSG_BENCH (LogLevel.START, R.string.msg_bench),
MSG_BENCH_ENC_TIME (LogLevel.INFO, R.string.msg_bench_enc_time),
MSG_BENCH_DEC_TIME (LogLevel.INFO, R.string.msg_bench_dec_time),
MSG_BENCH_SUCCESS (LogLevel.OK, R.string.msg_bench_success),
;
public final int mMsgId;

View File

@@ -26,6 +26,7 @@ import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
public class PgpSignEncryptResult extends InputPendingResult {
byte[] mDetachedSignature;
public long mOperationTime;
public void setDetachedSignature(byte[] detachedSignature) {
mDetachedSignature = detachedSignature;

View File

@@ -56,6 +56,10 @@ public class SignEncryptResult extends InputPendingResult {
return mResultBytes;
}
public ArrayList<PgpSignEncryptResult> getResults() {
return mResults;
}
public int describeContents() {
return 0;
}