Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View morgen-peschke's full-sized avatar

Morgen Peschke morgen-peschke

View GitHub Profile
@morgen-peschke
morgen-peschke / ExtensionMethodsOnCompanionObjects.scala
Created March 19, 2018 21:26
Example of how to create an Extension Method on a Companion Object
object ExtensionMethodsOnCompanionObjects {
implicit class ListFactoryOps(val list: List.type) extends AnyVal {
def fizzbuzz(n: Int): List[String] =
(0 to n).map {
case n if n % 15 == 0 => "FizzBuzz"
case n if n % 3 == 0 => "Fizz"
case n if n % 5 == 0 => "Buzz"
case n => n.toString
}.toList
@morgen-peschke
morgen-peschke / junit-create-list-benchmark
Last active August 29, 2015 14:14
Java Create List Benchmark
/* Results:
| Test Name | Time per round | Time in GC | Time in Benchmark |
|--------------------------------------------------+----------------+------------+-------------------|
| LinkedList Add only in front | 0.03 [+- 0.00] | 2.67 | 3.06 |
| LinkedList Add only in back | 0.03 [+- 0.01] | 2.61 | 3.01 |
| LinkedList Add in front and back | 0.03 [+- 0.00] | 2.66 | 3.16 |
| ArrayList Add only in front | 3.83 [+- 0.06] | 0.74 | 382.93 |
| ArrayList Add only in front with known size | 3.87 [+- 0.05] | 0.76 | 386.71 |
| ArrayList Add only in back | 0.01 [+- 0.01] | 0.69 | 0.87 |
| ArrayList Add only in back with known size | 0.01 [+- 0.01] | 0.76 | 0.93 |