Skip to content

Instantly share code, notes, and snippets.

@nitram509
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitram509/b6f836a697b405e5f440 to your computer and use it in GitHub Desktop.
Save nitram509/b6f836a697b405e5f440 to your computer and use it in GitHub Desktop.
JMacaroonsBenchmark
import com.github.nitram509.jmacaroons.Macaroon;
import com.github.nitram509.jmacaroons.MacaroonsBuilder;
import com.github.nitram509.jmacaroons.MacaroonsVerifier;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
public class JMacaroonsBenchmark {
private final static String serialized1 = "MDAyNGxvY2F0aW9uIGh0dHA6Ly93d3cuZXhhbXBsZS5vcmcKMDAyNmlkZW50aWZpZXIgd2UgdXNlZCBvdXIgc2VjcmV0IGtleQowMDJmc2lnbmF0dXJlIOPZ4CkIUmxMADmuFRFBFdl/3Wi/K6N5s0Kq8PYX0FUvCg==";
private final static String serialized2 = "MDAyNGxvY2F0aW9uIGh0dHA6Ly93d3cuZXhhbXBsZS5vcmcKMDAyNmlkZW50aWZpZXIgd2UgdXNlZCBvdXIgc2VjcmV0IGtleQowMDJmc2lnbmF0dXJlIFx0ik2r_V_yoLWrVhIMgCGRK1kawJAjtL_7xuG1TmZPCg";
@Benchmark
public void benchmark_Serialize_with_key_string() {
String location = "http://www.example.org";
String secretKey = "this is our super secret key; only we should know it.";
String identifier = "we used our secret key";
Macaroon macaroon = MacaroonsBuilder.create(location, secretKey, identifier);
macaroon.serialize();
}
@Benchmark
public void benchmark_Serialize_with_key_bytes() {
String location = "http://www.example.org";
byte[] secretKey = "this is our super secret key; only we should know it.".getBytes();
String identifier = "we used our secret key";
Macaroon macaroon = MacaroonsBuilder.create(location, secretKey, identifier);
macaroon.serialize();
}
@Benchmark
public void benchmark_Serialize_with_key_bytes_and_1_caveat() {
String location = "http://www.example.org";
byte[] secretKey = "this is our super secret key; only we should know it.".getBytes();
String identifier = "we used our secret key";
Macaroon macaroon = new MacaroonsBuilder(location, secretKey, identifier)
.add_first_party_caveat("first caveat")
.getMacaroon();
macaroon.serialize();
}
@Benchmark
public void benchmark_Serialize_with_key_bytes_and_2_caveats() {
String location = "http://www.example.org";
byte[] secretKey = "this is our super secret key; only we should know it.".getBytes();
String identifier = "we used our secret key";
Macaroon macaroon = new MacaroonsBuilder(location, secretKey, identifier)
.add_first_party_caveat("first caveat")
.add_first_party_caveat("second caveat")
.getMacaroon();
macaroon.serialize();
}
@Benchmark
public void benchmark_Serialize_with_key_bytes_and_3_caveats() {
String location = "http://www.example.org";
byte[] secretKey = "this is our super secret key; only we should know it.".getBytes();
String identifier = "we used our secret key";
Macaroon macaroon = new MacaroonsBuilder(location, secretKey, identifier)
.add_first_party_caveat("first caveat")
.add_first_party_caveat("second caveat")
.add_first_party_caveat("third caveat")
.getMacaroon();
macaroon.serialize();
}
@Benchmark
public void benchmark_Deserialize_and_Verify_key_string() {
String secretKey = "this is our super secret key; only we should know it";
Macaroon macaroon = MacaroonsBuilder.deserialize(serialized1);
new MacaroonsVerifier(macaroon).assertIsValid(secretKey);
}
@Benchmark
public void benchmark_Deserialize_and_Verify_key_bytes() {
final byte[] secretKey = "this is our super secret key; only we should know it".getBytes();
Macaroon macaroon = MacaroonsBuilder.deserialize(serialized2);
new MacaroonsVerifier(macaroon).assertIsValid(secretKey);
}
@Benchmark
public void benchmark_Deserialize() {
MacaroonsBuilder.deserialize(serialized1);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(JMacaroonsBenchmark.class.getSimpleName())
.forks(1)
.warmupIterations(3)
.measurementIterations(5)
.build();
new Runner(opt).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment