Skip to content

Commit

Permalink
testing performance for string commands parsing (is decent)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Feb 15, 2024
1 parent edfcfc0 commit 3d37a75
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mattmx.ktgui.commands.stringbuilder.syntax

import com.google.common.base.Stopwatch
import com.mattmx.ktgui.utils.StopWatch

class Parser(
val source: String
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mattmx.ktgui.commands.stringbuilder

import com.mattmx.ktgui.commands.usage.CommandUsageOptions
import com.mattmx.ktgui.utils.StopWatch
import org.bukkit.command.CommandSender

fun main() {
Expand Down
20 changes: 20 additions & 0 deletions api/src/main/kotlin/com/mattmx/ktgui/utils/StopWatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mattmx.ktgui.utils

import java.time.Duration

class StopWatch(
private val name: String = "sw"
) {
private var timeStart = 0L

fun start() = apply {
timeStart = System.nanoTime()
}

fun elapsed() = System.nanoTime() - timeStart

fun debug() {
val nanos = elapsed()
println(" [$name] took ${nanos}ns (${nanos / 1_000_000}ms${if (nanos > 100_000_000) ", " + Duration.ofNanos(nanos).pretty() else ""})")
}
}

0 comments on commit 3d37a75

Please sign in to comment.