distinctは遅いみたいです。 嘘でしたすいません.. (xuwei_kさんありがとうございます)
class Bench {
@Benchmark
def set2seq(): Unit = (1 to 100).combinations(2).toList.flatten.toSet.toSeq
@Benchmark
def distinct(): Unit = (1 to 100).combinations(2).toList.flatten.distinct
}
[info] Benchmark Mode Samples Score Score error Units
[info] f.Bench.set2seq thrpt 3 90.893 495.577 ops/s
[info] f.Bench.distinct thrpt 3 109.927 75.496 ops/s
正しくないやつ↓
@State(Scope.Thread)
class Bench {
val list: Seq[Int] = (1 to 100).combinations(2).toList.flatten
@Benchmark
def set2seq(): Unit = list.toSet.toSeq
@Benchmark
def distinct(): Unit = list.distinct
}
[info] Benchmark Mode Samples Score Score error Units
[info] f.Bench.distinct thrpt 3 13111.451 3086.943 ops/s
[info] f.Bench.set2seq thrpt 3 5717.012 4046.475 ops/s
benchmarkの問題っぽい。リストを作るタイミングの問題かな...