Skip to content

Add benchmarks for specialization #9752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,52 @@ class Functions {
def foo(x: => Int): Int = x
}

// outsmart JVM with storage in mutable array
var byName = new ByName
var arrByName = Array(byName, null)

@Benchmark
def byNameBench(): Int = 10000.times { byName.foo(6) }
def byNameBench(): Int = 10000.times {
// necessary to outsmart JVM
// remove it will result in 200x speed up
arrByName(1) = null
arrByName(0).foo(6)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out we also need this turnaround to defeat JVM optimization.



var fn = (x: Int) => x + 1
var arr = Array(fn, null)
@Benchmark
def lambdaBench(): Int = 10000.times { fn(2) }
def lambdaBench(): Int = 10000.times {
arr(1) = null
arr(0)(2)
}

class Func1[T](fn: T => Int) extends Function1[T, Int] {
def apply(x: T): Int = fn(x)
}
class Fn extends Func1(identity[Int])

var fn1: Function1[Int, Int] = new Fn
var arr1 = Array(fn1, null)

@Benchmark
def extendFun1Bench(): Int = 10000.times { fn1(12) }
def extendFun1Bench(): Int = 10000.times {
arr1(1) = null
arr1(0)(12)
}


class Func2 extends Function2[Int, Int, Int] {
def apply(i: Int, j: Int) = i + j
}

var fn2: Function2[Int, Int, Int] = new Func2
var arr2 = Array(fn2, null)

@Benchmark
def extendFun2Bench(): Int = 1000000.times { fn2(1300, 37) }
def extendFun2Bench(): Int = 10000.times {
arr2(1) = null
arr2(0)(1300, 37)
}
}