Last active
November 2, 2020 15:11
-
-
Save davidohana/b2a1e12795d0130afa32b4804d5734d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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