From 95e89bb16996b9e68a51f4c24942e6742c710e60 Mon Sep 17 00:00:00 2001 From: baba Date: Fri, 15 Apr 2022 18:40:15 +0900 Subject: [PATCH 1/2] Introduces a JMH-based set of benchmarks same as https://github.com/nulab/zxcvbn4j/pull/69 --- build.gradle | 3 ++ .../RandomPasswordMeasureBenchmark.java | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/jmh/java/com/nulabinc/zxcvbn/RandomPasswordMeasureBenchmark.java diff --git a/build.gradle b/build.gradle index 09d869f..0795daa 100644 --- a/build.gradle +++ b/build.gradle @@ -4,6 +4,7 @@ plugins { id 'signing' id 'jacoco' id 'com.github.kt3k.coveralls' version '2.12.0' + id "me.champeau.jmh" version "0.6.6" } group = 'com.nulab-inc' @@ -23,6 +24,8 @@ repositories { dependencies { testImplementation group: 'junit', name: 'junit', version: '4.13.2' + jmh group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.34' + jmh group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version:'1.34' } task compileModuleInfoJava(type: JavaCompile, dependsOn: compileJava) { diff --git a/src/jmh/java/com/nulabinc/zxcvbn/RandomPasswordMeasureBenchmark.java b/src/jmh/java/com/nulabinc/zxcvbn/RandomPasswordMeasureBenchmark.java new file mode 100644 index 0000000..76ba73b --- /dev/null +++ b/src/jmh/java/com/nulabinc/zxcvbn/RandomPasswordMeasureBenchmark.java @@ -0,0 +1,52 @@ +package com.nulabinc.zxcvbn; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +import java.io.IOException; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Thread) +@Warmup(iterations = 2) +@Measurement(iterations = 3) +@Fork(1) +public class RandomPasswordMeasureBenchmark { + + @Param({"8", "32", "128", "512", "1024"}) + private int passwordLength; + private String password; + Zxcvbn zxcvbn; + + @Setup + public void setup() throws IOException { + zxcvbn = new ZxcvbnBuilder() + .dictionaries(StandardDictionaries.loadAllDictionaries()) + .keyboards(StandardKeyboards.loadAllKeyboards()) + .build(); + + Random random = new Random(42); + StringBuilder sb = new StringBuilder(passwordLength); + for (int i = 0; i < passwordLength; i++) { + char c = (char) (random.nextInt() % Character.MAX_VALUE); + sb.append(c); + } + password = sb.toString(); + } + + @Benchmark + public Strength measure() { + return zxcvbn.measure(password); + } +} \ No newline at end of file From 569f85798811180c33a289fbda050aac54b4cd33 Mon Sep 17 00:00:00 2001 From: baba Date: Mon, 18 Apr 2022 14:01:05 +0900 Subject: [PATCH 2/2] Add a dependency on asm to fix compilation problem. --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0795daa..a650983 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,8 @@ repositories { dependencies { testImplementation group: 'junit', name: 'junit', version: '4.13.2' jmh group: 'org.openjdk.jmh', name: 'jmh-core', version: '1.34' - jmh group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version:'1.34' + jmh group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: '1.34' + jmh group: 'org.ow2.asm', name: 'asm', version: '9.3' } task compileModuleInfoJava(type: JavaCompile, dependsOn: compileJava) {