diff --git a/.gitattributes b/.gitattributes
index be29920..26071cd 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,2 @@
* text=auto
-MANIFEST text eol=crlf
+*.bat text eol=crlf
diff --git a/.gitignore b/.gitignore
index 3acd5f6..5d5350f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,5 @@
/build/
/.gradle/
-/.idea/*
-!/.idea/artifacts
-!/.idea/libraries
-!/.idea/kotlinc.xml
-!/.idea/modules.xml
-!/.idea/vcs.xml
+/.idea
+/application.conf
+*.iml
diff --git a/.idea/artifacts/dns_benchmark_jar.xml b/.idea/artifacts/dns_benchmark_jar.xml
deleted file mode 100644
index b919f45..0000000
--- a/.idea/artifacts/dns_benchmark_jar.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
- $PROJECT_DIR$/build/libs
-
-
-
-
-
-
-
-
-
-
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
deleted file mode 100644
index 2d95299..0000000
--- a/.idea/kotlinc.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml
deleted file mode 100644
index 30d5a17..0000000
--- a/.idea/libraries/KotlinJavaRuntime.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 3a0eb24..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..a3be7f1
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,88 @@
+import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+plugins {
+ id("com.github.johnrengelman.shadow") version "8.1.1"
+ kotlin("jvm") version "1.9.10"
+ kotlin("plugin.serialization") version "1.9.10"
+}
+
+val javaVersion = JavaVersion.VERSION_1_8
+val javaVersionNumber = javaVersion.name.substringAfter('_').replace('_', '.')
+val javaVersionMajor = javaVersion.name.substringAfterLast('_')
+
+val r8: Configuration by configurations.creating
+dependencies {
+ implementation(kotlin("serialization"))
+ implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:1.6.0")
+ r8("com.android.tools:r8:+")
+}
+
+
+tasks.withType {
+ kotlinOptions.jvmTarget = javaVersionNumber
+}
+
+tasks.withType {
+ sourceCompatibility = javaVersionNumber
+ targetCompatibility = javaVersionNumber
+}
+
+tasks.withType {
+ manifest {
+ attributes(mapOf("Main-Class" to "MainKt"))
+ }
+}
+
+tasks.withType {
+ archiveClassifier.set("shadow")
+ mergeServiceFiles()
+ minimize()
+ exclude("**/*.kotlin_*")
+}
+
+tasks {
+ assemble {
+ dependsOn(shadowJarMinified)
+ }
+}
+
+val shadowJarMinified = tasks.register("shadowJarMinified") {
+ dependsOn(configurations.runtimeClasspath)
+
+ val proguardRules = file("src/main/proguard-rules.pro")
+ inputs.files(tasks.shadowJar.get().outputs.files, proguardRules)
+
+ val r8File = layout.buildDirectory.file("libs/${base.archivesName.get()}-shadow-minified.jar").get().asFile
+ outputs.file(r8File)
+
+ classpath(r8)
+
+ mainClass.set("com.android.tools.r8.R8")
+ val javaHome = File(ProcessHandle.current().info().command().get()).parentFile.parentFile.canonicalPath
+
+ val args = mutableListOf(
+ //"--debug",
+ "--classfile",
+ "--output",
+ r8File.toString(),
+ "--pg-conf",
+ proguardRules.toString(),
+ "--lib",
+ javaHome,
+ )
+ args.add(tasks.shadowJar.get().outputs.files.joinToString(" "))
+
+ this.args = args
+
+ doFirst {
+ val javaHomeVersion = Runtime.getRuntime().exec("$javaHome/bin/java -version").run {
+ (inputStream.bufferedReader().readText() + errorStream.bufferedReader().readText()).split('"')[1]
+ }
+ check(JavaVersion.toVersion(javaHomeVersion).isCompatibleWith(javaVersion)) {
+ "Incompatible Java Versions: compile-target $javaVersionNumber, r8 runtime $javaHomeVersion (needs to be as new or newer)"
+ }
+
+ check(proguardRules.exists()) { "$proguardRules doesn't exist" }
+ }
+}
diff --git a/dns-benchmark.iml b/dns-benchmark.iml
deleted file mode 100644
index 4eba30b..0000000
--- a/dns-benchmark.iml
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..37f044b
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,3 @@
+kotlin.code.style=official
+org.gradle.caching=true
+org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..033e24c
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..ac72c34
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..fcb6fca
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,248 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..93e3f59
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..ea82c40
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,20 @@
+@file:Suppress("UnstableApiUsage")
+
+pluginManagement {
+ repositories {
+ mavenCentral()
+ google()
+ gradlePluginPortal()
+ }
+}
+
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ mavenCentral()
+ google()
+ maven { url = uri("https://jitpack.io") }
+ }
+}
+
+rootProject.name = "dns-benchmark"
diff --git a/src/main/kotlin/Config.kt b/src/main/kotlin/Config.kt
new file mode 100644
index 0000000..6c383dd
--- /dev/null
+++ b/src/main/kotlin/Config.kt
@@ -0,0 +1,74 @@
+@file:OptIn(ExperimentalSerializationApi::class)
+
+import java.io.File
+import kotlin.system.exitProcess
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.seconds
+import kotlinx.serialization.ExperimentalSerializationApi
+import kotlinx.serialization.MissingFieldException
+import kotlinx.serialization.Serializable
+import kotlinx.serialization.hocon.Hocon
+import kotlinx.serialization.hocon.decodeFromConfig
+import kotlinx.serialization.hocon.encodeToConfig
+import com.typesafe.config.ConfigFactory
+import com.typesafe.config.ConfigRenderOptions
+
+private val configRenderOptions = ConfigRenderOptions.defaults().setComments(true).setOriginComments(false).setJson(false)
+
+@Serializable
+data class Config(
+ /**
+ * The list of DNS-Servers to test. IPv4 or IPv6
+ */
+ val servers: List,
+ /**
+ * The domain to query.
+ * Will be formatted with two ints:
+ * a random prefix and the iteration count to generate unique requests
+ */
+ val domain: String,
+ /**
+ * The command to run.
+ * Will be formatted with two strings:
+ * the queried domain and the dns server.
+ * Example: `"drill %s @%s"`
+ */
+ val command: String,
+ /**
+ * The regex used to extract the time
+ */
+ val timeRegex: String,
+ /**
+ * How often each DNS server is queried
+ */
+ val repeat: Int,
+ /**
+ * The time to wait between queries to a server
+ */
+ val delay: Duration,
+) {
+ companion object {
+ fun load(): Config {
+ val file = File("application.conf")
+ if (!file.exists()) {
+ file.writeText(Config(emptyList(), "", "", "", 100, 1.seconds).toHocon())
+ printErr("Config not found, created empty: $file")
+ exitProcess(1)
+ }
+ try {
+ val config = ConfigFactory.parseFile(file)
+ return Hocon.decodeFromConfig(config)
+ } catch (e: MissingFieldException) {
+ printErr("Config incomplete, please add ${e.missingFields.joinToString()}")
+ exitProcess(1)
+ }
+ }
+ }
+
+ fun toHocon(): String {
+ return Hocon.encodeToConfig(this).root().render(configRenderOptions)
+ }
+}
+
+fun printErr(msg: Any) = System.err.println(msg)
+fun printErr(msg: String) = System.err.println(msg)
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 522438a..2a490d2 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -2,32 +2,22 @@ import kotlin.random.Random
@Suppress("UNREACHABLE_CODE", "KotlinRedundantDiagnosticSuppress")
fun main() {
- val servers = arrayOf(
- "1.1.1.1", "1.0.0.1", "2606:4700:4700::1111", "2606:4700:4700::1001", // Cloudflare
- "9.9.9.9", "149.112.112.112", "2620:fe::fe", "2620:fe::9", // Quad9
- "193.110.81.0", "185.253.5.0", "2a0f:fc80::", "2a0f:fc81::", // dns0.eu
- "8.8.8.8", "8.8.4.4", "2001:4860:4860::8888", "2001:4860:4860::8844", // Google
-// "62.109.121.1", "62.109.121.2", "2a01:c30::530", "2a01:c30::531", // O2
-// "79.143.183.251", "79.143.183.252", "213.136.95.10", "213.136.95.11", // Contabo
- "76.76.2.5", "76.76.10.5", "2606:1a40::5", "2606:1a40:1::5", // ControlD
- )
-
-// println(servers.joinToString("\n"))
-
- val results = servers.associateWith { mutableListOf() }
-
- val prefix = (1..9).joinToString("") { Random.nextInt(10).toString() }
+ println("dns-benchmark")
- val command: (String, String) -> String = { server: String, domain: String -> "drill $domain @$server" }
- val regex = Regex(";; Query time: (\\d+) msec")
+ val config = Config.load()
+ print("benchmarking ${config.servers.size} servers")
+ val results = config.servers.associateWith { mutableListOf() }
+ val prefix = Random.nextInt(from = 0, until = Int.MAX_VALUE)
+ val regex = Regex(config.timeRegex)
val runtime = Runtime.getRuntime()
- repeat(100) {
- val domain = "${prefix}${it}.binarynoise.de"
+ repeat(config.repeat) {
+ print(".")
+ val domain = config.domain.format(prefix, it)
for ((server, result) in results) {
- val process = runtime.exec(command(server, domain))
+ val process = runtime.exec(config.command.format(domain, server))
val exitCode = process.waitFor()
if (exitCode != 0) {
@@ -35,21 +25,23 @@ fun main() {
continue
}
- val out = process.inputReader().readLines()
- val err = process.errorReader().readLines()
-
+ val out = process.inputStream.bufferedReader().readLines()
+ val err = process.errorStream.bufferedReader().readLines()
check(err.isEmpty())
- val line = out.find { it.contains("Query time") }
+ val line = out.findLast { regex.matches(it) }
check(line != null)
val match = regex.find(line)
check(match != null)
- val time = match.groups[1]!!.value.toInt()
+ val time = match.groupValues[1].toInt()
result.add(time)
}
+ Thread.sleep(config.delay.inWholeMilliseconds)
}
+ repeat(3) { println() }
+
val table: List> = results.entries.map>, List> { (server, results) ->
results.mapTo(mutableListOf(server)) { it.toString() }
}.transpose()
@@ -61,6 +53,7 @@ fun main() {
* Given a list of lists (ie a matrix), transpose it
*/
fun List>.transpose(): List> {
+ if (this.isEmpty()) return emptyList()
return (this[0].indices).map { i -> (this.indices).map { j -> this[j][i] } }
}
@@ -68,5 +61,6 @@ fun List>.transpose(): List> {
* Given an array of arrays (ie a matrix), transpose it
*/
inline fun Array>.transpose(): Array> {
+ if (this.isEmpty()) return emptyArray()
return Array(this[0].size) { i -> Array(this.size) { j -> this[j][i] } }
}
diff --git a/src/main/proguard-rules.pro b/src/main/proguard-rules.pro
new file mode 100644
index 0000000..ce5d95f
--- /dev/null
+++ b/src/main/proguard-rules.pro
@@ -0,0 +1,10 @@
+-dontobfuscate
+-keepattributes SourceFile, LineNumberTable, Exception, *Annotation*, InnerClasses, EnclosingMethod, Signature
+
+-allowaccessmodification
+-dontskipnonpubliclibraryclasses
+-dontskipnonpubliclibraryclassmembers
+
+-keep,allowoptimization class MainKt {
+ public static void main(java.lang.String[]);
+}
diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF
deleted file mode 100644
index 82c7964..0000000
--- a/src/main/resources/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Main-Class: MainKt
-