Skip to content

Instantly share code, notes, and snippets.

@blast-hardcheese
Last active March 19, 2022 23:15
Show Gist options
  • Save blast-hardcheese/5bda592624b5842373997f71e2622df8 to your computer and use it in GitHub Desktop.
Save blast-hardcheese/5bda592624b5842373997f71e2622df8 to your computer and use it in GitHub Desktop.
Benchmarking http4s DigestAuth changes
// Just some functions to run in consoleQuick.
// To start, execute the following, replacing $TIP with a unique identifier, on each branch that you wish to test
// for i in {1..40}; do
// sbtn 'server / testOnly org.http4s.server.middleware.authentication.AuthenticationSuite' \
// | grep '^ +' \
// | sed 's/.\[0J$//' \
// | tee -a /tmp/$TIP.txt
// done
//
// Then, in consoleQuick, after copy/pasting these lines,
//
// println(calc("/tmp/$TIP.txt"))
//
// for each $TIP
import scala.concurrent.duration._
object BreakUp {
def unapply(raw: String): Option[(String, scala.concurrent.duration.FiniteDuration)] = {
val _ +: _ +: _ +: (xs :+ s) = raw.split(' ').toSeq
Some((xs.mkString(" "), scala.concurrent.duration.FiniteDuration((s.stripSuffix("s").toDouble * 1000).toLong, scala.concurrent.duration.MILLISECONDS)))
}
}
def calc(f: String) =
scala.io.Source.fromFile(new java.io.File(f))
.getLines()
.map({ case BreakUp(s, t) => (s, t) })
.toSeq
.groupBy(_._1)
.view
.mapValues(xs => (xs.foldLeft(FiniteDuration(0, MILLISECONDS))({ case (acc, (_, next)) => acc + next }) / xs.length.toLong).toMillis)
.toSeq
.sortBy(_._1)
.map({ case (s, t) => s"${s}: ${t}ms" })
.mkString("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment