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
def append2Immutable(noTimes: Long): Unit = { | |
@scala.annotation.tailrec | |
def go(l: List[Int], i: Long = 0): List[Int] = { | |
if (i > noTimes) l | |
else go(l :+ 0, i + 1) | |
} | |
go(List()) | |
} | |
def append2Mutable(noTimes: Long): 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
def timeOf(action: => Unit, noTimes: Int = 10, multiplier: Int = 1): Double = { | |
import java.util.concurrent.TimeUnit | |
val runtime = Runtime.getRuntime | |
val result = (1 to noTimes + 1) map { _ => | |
val startTime = System.nanoTime | |
var i = 0 | |
while (i < multiplier) { | |
action | |
i += 1 | |
} |
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 Loan[T <: {def close()}] private(resources: T) { | |
def map[U](func: T => U): Option[U] = | |
try { | |
Option(func(resources)) | |
} catch { | |
case ex: Throwable => | |
ex.printStackTrace() | |
None | |
} finally { | |
if (resources != null) |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication4 | |
{ | |
class Fraction | |
{ |
NewerOlder