This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String test = if(1 == 1) "a" else "b"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ScalarTernaryTyped extends App{ | |
class TernaryIfThenClause[X](c: => Boolean, tc: => X){ | |
lazy val cond = c | |
lazy val thenClause = tc | |
} | |
implicit class TernaryAssoc(cond: => Boolean){ | |
def ??[X](thenClause: => X) = new TernaryIfThenClause(cond, thenClause) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit class TernaryElseClause(elseClause: => Unit){ | |
def ::(ifThenClause: TernaryIfThenClause) = | |
if(ifThenClause.cond) ifThenClause.thenClause else elseClause | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit class TernaryAssoc(cond: => Boolean){ | |
def ??(thenClause: => Unit) = new TernaryIfThenClause(cond, thenClause) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TernaryIfThenClause(c: => Boolean, tc: => Unit){ | |
lazy val cond = c | |
lazy val thenClause = tc | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class TernaryIfThenClause(c: => Boolean, tc: => Unit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val list = 1 :: 2 :: 3 :: 4 :: Nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ScalarPuzzle extends App { | |
implicit class TernaryOps(cond: => Boolean) { | |
def ??(thenBlock: => Unit) = new { | |
def ::(elseBlock: => Unit): Unit = | |
if(cond) thenBlock else elseBlock | |
} | |
} | |
(1 + 1 == 2) ?? println("True") :: println("False") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Iteration no. | Time[ms] | |
---|---|---|
1 | 33656.406 | |
2 | 16100.784 | |
3 | 10734.691 | |
4 | 13656.410 | |
5 | 7297.651 | |
6 | 7732.481 | |
7 | 5081.496 | |
8 | 3020.896 | |
9 | 3126.210 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Metrics | Java | C++ | C++ optimized | C++ off-heap | C++ combined | |
---|---|---|---|---|---|---|
Iterations | 10 | 10 | 10 | 10 | 10 | |
Min. iteration time [ms] | 4030.221 | 7890.256 | 5136.895 | 6250.862 | 2656.214 | |
Max. iteration time [ms] | 9432.062 | 7941.776 | 5166.630 | 6286.141 | 2665.393 | |
Avg. iteration time [ms] | 6251.026 | 7910.600 | 5155.023 | 6267.842 | 2662.243 |