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

View File

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