Github user cloud-fan commented on the pull request:
https://github.com/apache/spark/pull/6182#issuecomment-102359922
Use the same benchmark:
```scala
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.types._
case class Floor(child: Expression) extends UnaryExpression with Predicate {
override def foldable = child.foldable
def nullable = child.nullable
override def toString = s"Floor $child"
override def eval(input: Row): Any = {
child.eval(input) match {
case null => null
case ts: Int => ts - ts % 300
}
}
}
object T {
def benchmark(count: Int, expr: Expression): Unit = {
var i = 0
val row = new GenericRow(Array[Any](123, 21, 42))
val s = System.currentTimeMillis()
while (i < count) {
expr.eval(row)
i += 1
}
val e = System.currentTimeMillis()
println (s"${expr.getClass.getSimpleName} -- ${e - s} ms")
}
def main(args: Array[String]) {
def func(ts: Int) = ts - ts % 300
val udf0 = ScalaUdf(func _, IntegerType, BoundReference(0, IntegerType,
true) :: Nil)
val udf1 = Floor(BoundReference(0, IntegerType, true))
benchmark(1000000, udf0)
benchmark(1000000, udf0)
benchmark(1000000, udf0)
benchmark(1000000, udf1)
benchmark(1000000, udf1)
benchmark(1000000, udf1)
}
}
```
before:
ScalaUdf -- 151 ms
ScalaUdf -- 127 ms
ScalaUdf -- 128 ms
Floor -- 23 ms
Floor -- 4 ms
Floor -- 5 ms
after:
ScalaUdf -- 28 ms
ScalaUdf -- 12 ms
ScalaUdf -- 8 ms
Floor -- 22 ms
Floor -- 4 ms
Floor -- 4 ms
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]