Skip to content

Instantly share code, notes, and snippets.

scala> for(masked <- 0 until 8) { println("Bits: 0xff & masked bits (" + masked + ") => " + (256 - (255 & (1 << masked)))) }
Bits: 0xff & masked bits (0) => 255
Bits: 0xff & masked bits (1) => 254
Bits: 0xff & masked bits (2) => 252
Bits: 0xff & masked bits (3) => 248
Bits: 0xff & masked bits (4) => 240
Bits: 0xff & masked bits (5) => 224
Bits: 0xff & masked bits (6) => 192
Bits: 0xff & masked bits (7) => 128
@djk29a
djk29a / timer_obj.scala
Last active October 4, 2016 01:28
Simple Scala timer I haven't tried to use since Scala 2.08
object Timer {
def time[R](block: => R): Pair[Long,_] = {
val t0 = System.nanoTime()
val result = block
val diff = System.nanoTime() - t0
// Post-timing processing can be added here, maybe
// an optional argument to this method?
Pair(diff, result)
}
}