Skip to content

Commit

Permalink
Style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DLochmelis33 committed Aug 4, 2024
1 parent 4fc7eb1 commit fa868fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ fun LitmusResult.overallStatus(): LitmusOutcomeType {
}

fun List<LitmusResult>.mergeResults(): LitmusResult {
data class LTOutcomeStatTempData(var count: Long, val type: LitmusOutcomeType)
data class LTOutcomeStatsAccumulator(var count: Long, val type: LitmusOutcomeType)

val statMap = mutableMapOf<LitmusOutcome, LTOutcomeStatTempData>()
val statMap = mutableMapOf<LitmusOutcome, LTOutcomeStatsAccumulator>()
for (stat in this.flatten()) {
val tempData = statMap.getOrPut(stat.outcome) { LTOutcomeStatTempData(0L, stat.type) }
if (tempData.type != stat.type) error("merging conflicting stats: ${stat.outcome} is both ${stat.type} and ${tempData.type}")
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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class ThreadlikeRunner : LitmusRunner() {
if (i % syncPeriod == 0) barrier.await()
states[i].testFunction()
}
rangeResult = calcStats(states.view(resultCalcRange).asIterable(), test.outcomeSpec, test.outcomeFinalizer)
// performance optimization: each thread takes a portion of states and calculates stats for it
rangeResult = calcStats(states.view(resultCalcRange), test.outcomeSpec, test.outcomeFinalizer)
}

private data class ThreadContext<S : Any>(
Expand Down
7 changes: 5 additions & 2 deletions core/src/commonMain/kotlin/org/jetbrains/litmuskt/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ expect fun cpuCount(): Int
@Suppress("UNCHECKED_CAST")
fun <S> TypedArray(size: Int, init: (Int) -> S): Array<S> = Array<Any?>(size, init) as Array<S>

fun <S> Array<S>.view(range: IntRange): Sequence<S> = sequence {
/**
* Returns a lazy iterable that iterates over a portion of the underlying array.
*/
fun <S> Array<S>.view(range: IntRange): Iterable<S> = sequence {
for (i in range) yield(this@view[i])
}
}.asIterable()

/**
* Split a range into [n] parts of equal (+/- 1) length.
Expand Down

0 comments on commit fa868fc

Please sign in to comment.