Skip to content

Instantly share code, notes, and snippets.

@davidohana
Last active November 2, 2020 15:11
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 davidohana/b2a1e12795d0130afa32b4804d5734d8 to your computer and use it in GitHub Desktop.
Save davidohana/b2a1e12795d0130afa32b4804d5734d8 to your computer and use it in GitHub Desktop.
import davidoh.profiling.*
import java.security.MessageDigest
import kotlin.math.sqrt
fun main() {
val profiler: Profiler = SimpleProfiler(resetAfterSampleCount = 200000)
println("app started")
profiler.startSection("init")
val md5 = MessageDigest.getInstance("MD5")
val sha1 = MessageDigest.getInstance("SHA-1")
val sha256 = MessageDigest.getInstance("SHA-256")
val r = java.util.Random()
val bytes = ByteArray(10000)
r.nextBytes(bytes)
profiler.endSection()
while (true) {
profiler.startSection("total")
profiler.startSection("hashing")
profiler.startSection("md5")
md5.digest(bytes)
profiler.endSection()
profiler.startSection("sha256")
sha256.digest(bytes)
profiler.endSection()
profiler.startSection("sha1")
sha1.digest(bytes)
profiler.endSection()
profiler.endSection("hashing")
profiler.startSection("random")
val randNum = r.nextDouble() * 1000000 + 1
profiler.endSection()
profiler.startSection("sqrt")
sqrt(randNum)
profiler.endSection()
profiler.endSection("total")
if (profiler.report(10))
println("-----")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment