Github user witgo commented on the pull request:

    https://github.com/apache/spark/pull/332#issuecomment-40626222
  
    I don't think macros is faster than the inline method
    ```scala
    import scala.compat.Platform
    
    class Log(val flag: Boolean) {
    
      def logFunction0(msg: => String) {
        if (flag)
          println(msg)
      }
    
      def logString(msg: String) {
        if (flag)
          println(msg)
      }
    
      @inline
      def logInline(msg: => String) {
        if (flag)
          println(msg)
      }
    }
    
    val log = new Log(false)
    var startTime = Platform.currentTime
    var i = 0
    while (i < 1000000) {
      log.logInline("" + Thread.currentThread.getStackTrace().
        toSeq.take(10).mkString("\\n"))
      i += 1
    }
    var stopTime = Platform.currentTime
    Platform.collectGarbage
    println("logInline: " + (stopTime - startTime) + " ms")
    
    startTime = Platform.currentTime
    i = 0
    while (i < 1000000) {
      log.logFunction0("" + Thread.currentThread.getStackTrace().
        toSeq.take(10).mkString("\\n"))
      i += 1
    }
    stopTime = Platform.currentTime
    Platform.collectGarbage
    println("logFunction0: " + (stopTime - startTime) + " ms")
    
    startTime = Platform.currentTime
    i = 0
    while (i < 1000000) {
      log.logString("" + Thread.currentThread.getStackTrace().
        toSeq.take(10).mkString("\\n"))
      i += 1
    }
    stopTime = Platform.currentTime
    Platform.collectGarbage
    println("logString: " + (stopTime - startTime) + " ms")
    ````
        
    =>
    
    1.
    
        logInline: 9 ms
        logFunction0: 14 ms
        logString: 29114 ms
    
    2.
    
        logInline: 10 ms
        logFunction0: 13 ms
        logString: 28876 ms
    3.
    
        logInline: 9 ms
        logFunction0: 13 ms
        logString: 28521 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.
---

Reply via email to