-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from JetBrains-Research/dev-performance
Performance improvements (let each thread collect a portion of results)
- Loading branch information
Showing
9 changed files
with
120 additions
and
45 deletions.
There are no files selected for viewing
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
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
44 changes: 44 additions & 0 deletions
44
core/src/commonMain/kotlin/org/jetbrains/litmuskt/LitmusResult.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jetbrains.litmuskt | ||
|
||
typealias LitmusResult = List<LitmusOutcomeStats> | ||
|
||
fun LitmusResult.generateTable(): String { | ||
val totalCount = sumOf { it.count } | ||
val table = this.sortedByDescending { it.count }.map { | ||
val freq = it.count.toDouble() / totalCount | ||
listOf( | ||
it.outcome.toString(), | ||
it.type.toString(), | ||
it.count.toString(), | ||
if (freq < 1e-5) "<0.001%" else "${(freq * 100).toString().take(6)}%" | ||
) | ||
} | ||
val tableHeader = listOf("outcome", "type", "count", "frequency") | ||
return (listOf(tableHeader) + table).tableFormat(true) | ||
} | ||
|
||
fun LitmusResult.totalCount() = sumOf { it.count } | ||
|
||
fun LitmusResult.overallStatus(): LitmusOutcomeType { | ||
var isInteresting = false | ||
for (stat in this) when (stat.type) { | ||
LitmusOutcomeType.FORBIDDEN -> return LitmusOutcomeType.FORBIDDEN | ||
LitmusOutcomeType.INTERESTING -> isInteresting = true | ||
LitmusOutcomeType.ACCEPTED -> {} // ignore | ||
} | ||
return if (isInteresting) LitmusOutcomeType.INTERESTING else LitmusOutcomeType.ACCEPTED | ||
} | ||
|
||
fun List<LitmusResult>.mergeResults(): LitmusResult { | ||
data class LTOutcomeStatsAccumulator(var count: Long, val type: LitmusOutcomeType) | ||
|
||
val statMap = mutableMapOf<LitmusOutcome, LTOutcomeStatsAccumulator>() | ||
for (stat in this.flatten()) { | ||
val tempData = statMap.getOrPut(stat.outcome) { LTOutcomeStatsAccumulator(0L, stat.type) } | ||
if (tempData.type != stat.type) { | ||
error("merging conflicting stats: ${stat.outcome} is both ${stat.type} and ${tempData.type}") | ||
} | ||
tempData.count += stat.count | ||
} | ||
return statMap.map { (outcome, tempData) -> LitmusOutcomeStats(outcome, tempData.count, tempData.type) } | ||
} |
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
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
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
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
28 changes: 28 additions & 0 deletions
28
core/src/commonTest/kotlin/org/jetbrains/litmuskt/UtilTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jetbrains.litmuskt | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class UtilTest { | ||
|
||
@Test | ||
fun testRangeSplitEqual() { | ||
assertEquals( | ||
listOf(0..<4, 4..<8, 8..<11), | ||
(0..<11).splitEqual(3) | ||
) | ||
assertEquals( | ||
listOf(0..<3, 3..<5, 5..<7, 7..<9, 9..<11), | ||
(0..<11).splitEqual(5) | ||
) | ||
assertEquals( | ||
listOf(0..<500, 500..<1000), | ||
(0..<1000).splitEqual(2) | ||
) | ||
assertEquals( | ||
listOf(1..1, 2..2), | ||
(1..2).splitEqual(2) | ||
) | ||
} | ||
|
||
} |
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