File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .openjdk .jmh .samples
2
+
3
+ import org .openjdk .jmh .annotations ._
4
+
5
+ import java .util .concurrent .TimeUnit
6
+
7
+ object implicitClasses {
8
+
9
+ implicit final class ImplicitStandard [A ](val oa : Option [A ]) { def bar = oa.isDefined }
10
+ implicit final class ImplicitAnyVal [A ](val oa : Option [A ]) extends AnyVal { def bar = oa.isDefined }
11
+
12
+ }
13
+
14
+ object implicitFunctions {
15
+
16
+ final class ImplicitStandard [A ](val oa : Option [A ]) { def bar = oa.isDefined }
17
+ final class ImplicitAnyVal [A ](val oa : Option [A ]) extends AnyVal { def bar = oa.isDefined }
18
+
19
+ implicit def toStandard [A ](oa : Option [A ]) = new ImplicitStandard (oa)
20
+ implicit def toAnyVal [A ](oa : Option [A ]) = new ImplicitAnyVal (oa)
21
+ }
22
+
23
+ @ State (Scope .Thread )
24
+ @ BenchmarkMode (Array (Mode .AverageTime ))
25
+ @ OutputTimeUnit (TimeUnit .NANOSECONDS )
26
+ class ImplicitClassTest {
27
+
28
+
29
+ val option = Option (42 )
30
+
31
+ @ Benchmark
32
+ def testClassStandard = {
33
+ import implicitClasses .ImplicitStandard
34
+ option.bar
35
+ }
36
+
37
+ @ Benchmark
38
+ def testClassAnyVal = {
39
+ import implicitClasses .ImplicitAnyVal
40
+ option.bar
41
+ }
42
+
43
+ @ Benchmark
44
+ def testFunctionStandard = {
45
+ import implicitFunctions .toStandard
46
+ option.bar
47
+ }
48
+
49
+ @ Benchmark
50
+ def testFunctionAnyVal = {
51
+ import implicitFunctions .toAnyVal
52
+ option.bar
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments