feat: add some stopwatch points

This commit is contained in:
Assasinnys 2020-05-11 21:25:18 +03:00
parent c769ef6b61
commit 015a94575f
2 changed files with 15 additions and 5 deletions

View File

@ -41,13 +41,13 @@ class AStarMainFile {
}
do {
val sw = Stopwatch().start()
if (checkForFinish()) {
println("${consoleStringCounter()} Finish found.")
printTheFoundPath()
return
}
sw.stopWithConsoleOutput("CheckForFinish time: ")
val selectedStarPoint = findStarPointWithMinCost()
findNeighbours(selectedStarPoint)
openedList.remove(selectedStarPoint)
@ -69,15 +69,23 @@ class AStarMainFile {
}
private fun findStarPointWithMinCost(): StarPoint {
val sw = Stopwatch().start()
return openedList.minBy { starPoint -> starPoint.costF }!!.also { nextStarPoint ->
println("Min cost star point: G = ${nextStarPoint.costG}, F = ${nextStarPoint.costF}, H = ${nextStarPoint.costH} " +
"dist = ${nextStarPoint.distance}, start = ${nextStarPoint.previousStarPoint == startStarPoint}")
sw.stopWithConsoleOutput("FIND MIN COST TIME: ")
println(
"Min cost star point: G = ${nextStarPoint.costG}, F = ${nextStarPoint.costF}, H = ${nextStarPoint.costH} " +
"dist = ${nextStarPoint.distance}, start = ${nextStarPoint.previousStarPoint == startStarPoint}"
)
}
}
private fun findNeighbours(starPoint: StarPoint) {
val sw1 = Stopwatch().start()
val sw2 = Stopwatch().start()
val reader = file.bufferedReader().lines()
sw2.stopWithConsoleOutput("READ:LINES time: ")
reader.forEach { line ->
val sArray = line.split(" ")
val coords = Coordinates(
sArray[1].toDouble(),
@ -122,6 +130,7 @@ class AStarMainFile {
}
}
reader.close()
sw1.stopWithConsoleOutput("Find neighbors time (openListSize = ${openedList.size}): ")
}
private fun printTheFoundPath(): Int {

View File

@ -3,8 +3,9 @@ package elite.utils
class Stopwatch {
private var startTime: Long = 0L
fun start() {
fun start(): Stopwatch {
startTime = System.currentTimeMillis()
return this
}
fun stopWithConsoleOutput(prefix: String = "Time: ") {