Changeset 2bb0ca9


Ignore:
Timestamp:
Aug 26, 2017 8:41:12 PM (3 years ago)
Author:
str4d <str4d@…>
Branches:
master
Children:
40642c8
Parents:
d828ed4
Message:

Use I2PAppContext for obtaining instances of AES and SHA256

This gives a more realistic benchmark of how the rest of the I2P codebase
experiences these calls.

Location:
benchmarks/java/src/net/i2p/crypto
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • benchmarks/java/src/net/i2p/crypto/AESBench.java

    rd828ed4 r2bb0ca9  
    3232    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    3333    SessionKey key;
    34     CryptixAESEngine aes;
    3534    byte[] iv = new byte[16];
    3635    byte[] origPT = new byte[1024];
     
    4746        ctx.random().nextBytes(iv);
    4847        ctx.random().nextBytes(origPT);
    49         aes = new CryptixAESEngine(ctx);
    50         aes.encrypt(origPT, 0, origCT, 0, key, iv, len);
     48        ctx.aes().encrypt(origPT, 0, origCT, 0, key, iv, len);
    5149    }
    5250
    5351    @Benchmark
    5452    public void encrypt() {
    55         aes.encrypt(origPT, 0, encrypted, 0, key, iv, len);
     53        ctx.aes().encrypt(origPT, 0, encrypted, 0, key, iv, len);
    5654    }
    5755
    5856    @Benchmark
    5957    public void decrypt() {
    60         aes.decrypt(origCT, 0, decrypted, 0, key, iv, len);
     58        ctx.aes().decrypt(origCT, 0, decrypted, 0, key, iv, len);
    6159    }
    6260
  • benchmarks/java/src/net/i2p/crypto/SHA256Bench.java

    rd828ed4 r2bb0ca9  
    11package net.i2p.crypto;
    22
    3 import java.security.MessageDigest;
    4 import java.security.NoSuchAlgorithmException;
    5 import java.util.Random;
    63import java.util.concurrent.TimeUnit;
    74
     
    2118import org.openjdk.jmh.runner.options.Options;
    2219import org.openjdk.jmh.runner.options.OptionsBuilder;
     20
     21import net.i2p.I2PAppContext;
     22import net.i2p.data.Hash;
    2323
    2424/**
     
    5151@State(Scope.Benchmark)
    5252public class SHA256Bench {
    53     MessageDigest md;
     53    I2PAppContext ctx = I2PAppContext.getGlobalContext();
    5454
    5555    @Param({"40", "387", "10240"})
     
    5959
    6060    @Setup
    61     public void prepare() throws NoSuchAlgorithmException {
    62         md = MessageDigest.getInstance("SHA-256");
     61    public void prepare() {
    6362        data = new byte[len];
    64         Random r = new Random();
    65         r.nextBytes(data);
     63        ctx.random().nextBytes(data);
    6664    }
    6765
    6866    @Benchmark
    69     public byte[] digest() {
    70         md.reset();
    71         return md.digest(data);
     67    public Hash calculateHash() {
     68        return ctx.sha().calculateHash(data);
    7269    }
    7370
Note: See TracChangeset for help on using the changeset viewer.