File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
bench-run/src/main/scala/dotty/tools/benchmarks/specialization Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ package dotty .tools .benchmarks .specialization
2
+
3
+ import org .openjdk .jmh .annotations ._
4
+ import scala .util .Random
5
+
6
+ class Functions {
7
+ extension (x : Int )
8
+ inline def times (op : => Unit ): Unit = {
9
+ var count = 0
10
+ while count < x do
11
+ op
12
+ count += x
13
+ }
14
+
15
+ class ByName {
16
+ def foo (x : => Int ): Int = x
17
+ }
18
+
19
+ @ Benchmark
20
+ def byNameBench () = 10000 .times {
21
+ val a = new ByName
22
+ var list = List (a)
23
+ list.head.foo(6 ) + 10
24
+ }
25
+
26
+ @ Benchmark
27
+ def lambdaBench () = 10000 .times {
28
+ val fn = (x : Int ) => x + 1
29
+ var list = List (fn)
30
+ list.head(2 )
31
+ }
32
+
33
+ class Func1 [T ](fn : T => Int ) extends Function1 [T , Int ] {
34
+ def apply (x : T ): Int = fn(x)
35
+ }
36
+ class Fn extends Func1 (identity[Int ])
37
+
38
+ @ Benchmark
39
+ def extendFun1Bench () = 10000 .times {
40
+ val a : Function1 [Int , Int ] = new Fn
41
+ var list = List (a)
42
+ list.head(123 ) + 10
43
+ }
44
+
45
+ class Func2 extends Function2 [Int , Int , Int ] {
46
+ def apply (i : Int , j : Int ) = i + j
47
+ }
48
+
49
+ @ Benchmark
50
+ def extendFun2Bench () = 10000 .times {
51
+ val a : Function2 [Int , Int , Int ] = new Func2
52
+ var list = List (a)
53
+ list.head(1300 , 37 ) + 100
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments