« Return to Thread: Thoughts about RichObjects, Implicit convertions and performance

Re: Thoughts about RichObjects, Implicit convertions and performance

by Viktor Klang :: Rate this Message:

Reply to Author | View in Thread

I'd like:

object MyImplicits
{
//Syntax
//      implicit[targetType] def methodName[type params](params) : returnType = { expr }


//i.e
         implicit[String] def isAllDigits = this.matches("^\\d+$")

         implicit[Z <: AnyRef] def asInstanceOf[T](implicit clasz : Manifest[T]) : clasz.cast(this)
}

//usage:

import MyImplicits._

"0000".isAllDigits

5.asInstanceOf[Fajita] //Yes, this example is the very definition of WTF

On Tue, Mar 24, 2009 at 7:42 AM, Johannes Rudolph <johannes.rudolph@...> wrote:
On Tue, Mar 24, 2009 at 7:23 AM, David Hall <dlwh@...> wrote:
> Second observation, your benchmarking (below) is the "wrong" way to
> benchmark JVM code because of the peculiarities of hotspot. You should
> wrap these calls in a method and call it at least 10,000 times in a
> method before clocking speeds. HotSpot can do amazing things when you
> give it a chance.
>
> That said, my understanding* is that HotSpot does not (yet**) do a
> great job removing object creations, which is what is needed to really
> make implicits faster.

Right, see
http://wikis.sun.com/display/HotSpotInternals/MicroBenchmarks
for some tips how to fix microbenchmarks with the Hotspot compiler of
the OpenJDK. You can use -XX:+PrintCompilation VM option (with OpenJDK
or Sun JVM) to see when methods get JIT-compiled. In this particular
case my tries showed, that the method is compiled just after (while?)
the first run, so doing 10 iterations of the whole method should
suffice.

Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net



--
Viktor Klang
Senior Systems Analyst

 « Return to Thread: Thoughts about RichObjects, Implicit convertions and performance