1
- /*
2
1
package benchmark
3
2
4
- import algorithms.sort.returnBubbleSort
5
- import algorithms.sort.heapSort
6
-
7
- import org.openjdk.jmh.annotations.*
3
+ import algorithms .sort .*
4
+ import org .openjdk .jmh .annotations ._
8
5
9
6
import java .util .concurrent .TimeUnit
10
- import scala.collection.mutable
11
7
import scala .util .Random
12
8
13
- // sbt jmh / run -i 5 -wi 2 -f1 -t1
14
9
@ BenchmarkMode (Array (Mode .AverageTime ))
15
10
@ OutputTimeUnit (TimeUnit .MILLISECONDS )
16
11
@ State (Scope .Thread )
17
- @Warmup(iterations = 2) // Reduce warm-up iterations (default is 5)
18
- @Measurement(iterations = 5) // Reduce total benchmark iterations (default is 10)
19
- @Fork(1) // Reduce forks (default is 3)
12
+ @ Warmup (iterations = 2 )
13
+ @ Measurement (iterations = 5 )
14
+ @ Fork (1 )
20
15
class SortingBenchmark {
21
16
22
- var data: Array[Int] = new Array[Int](5000)
17
+ var data : Array [Int ] = new Array [Int ](500 ) // Smaller dataset for quick benchmarking
23
18
24
- @Setup(Level.Iteration) // Runs before each benchmark iteration
19
+ @ Setup (Level .Iteration )
25
20
def prepare (): Unit = {
26
- data = Array.fill(5000 )(Random.nextInt(1000000 )) // Large random dataset
21
+ data = Array .fill(500 )(Random .nextInt(500 )) // Smaller random dataset
27
22
}
28
23
29
24
@ Benchmark
@@ -35,5 +30,15 @@ class SortingBenchmark {
35
30
def benchmarkHeapSort (): Array [Int ] = {
36
31
heapSort(data.clone())
37
32
}
33
+
34
+ @ Benchmark
35
+ def benchmarkCountingSort (): Array [Int ] = {
36
+ countingSort(data.clone(), 500 )
37
+ }
38
+
39
+ @ Benchmark
40
+ def benchmarkInsertionSort (): Array [Int ] = {
41
+ returnInsertionSort(data.clone())
42
+ }
43
+
38
44
}
39
- */
0 commit comments