File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
bench-micro/src/main/scala/dotty/tools/benchmarks/inlinetraits Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ package dotty .tools .benchmarks .inlinetraits
2
+
3
+ import org .openjdk .jmh .annotations ._
4
+ import java .util .concurrent .TimeUnit .{SECONDS , MILLISECONDS }
5
+ import scala .util .Random
6
+
7
+ // @BenchmarkMode(Array(Mode.SampleTime))
8
+ @ Fork (3 )
9
+ @ Threads (3 )
10
+ @ Warmup (iterations = 5 , time = 10 , timeUnit = SECONDS )
11
+ @ Measurement (iterations = 10 , time = 10 , timeUnit = SECONDS )
12
+ // @OutputTimeUnit(MILLISECONDS)
13
+ @ State (Scope .Benchmark )
14
+ class Boxing {
15
+ class Wrapper [T ](val x : T )
16
+ class IntWrapper (val x : Int )
17
+
18
+ val numbers = 1 to 1000000
19
+ val ws = numbers.map(Wrapper (_))
20
+ val iws = numbers.map(IntWrapper (_))
21
+
22
+ @ Benchmark
23
+ def noUnboxing : Int = iws.map(w => IntWrapper (w.x* w.x + 2 * w.x)).foldLeft(0 )(_ + _.x)
24
+
25
+ @ Benchmark
26
+ def withUnboxing : Int = ws.map(w => Wrapper (w.x* w.x + 2 * w.x)).foldLeft(0 )(_ + _.x)
27
+ }
You can’t perform that action at this time.
0 commit comments