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
| scala> trait A | |
| defined trait A | |
| scala> | |
| scala> class B extends A | |
| defined class B | |
| scala> class C extends A | |
| defined class C |
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
| trait ArraySummer[-T] { | |
| def sum(t: T): Float | |
| } | |
| /** one TypeClass per concrete implementation */ | |
| object SpecificSummers { | |
| implicit object SimpleWrappedFloatArraySummer extends ArraySummer[SimpleWrappedFloatArray] { | |
| def sum(arr: SimpleWrappedFloatArray): Float = { | |
| ... | |
| } |
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
| trait ArrayLike[@specialized T] { | |
| def apply(idx: Int) : T | |
| def update(idx: Int, value: T) | |
| def length: Int | |
| def size: Int = length | |
| } | |
| def sumArrayLike(arr: ArrayLike[Float]): Float = { | |
| var idx = 0 | |
| var sum = 0f |
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 n = 1e7.toInt | |
| val (rawArray, rawBB, rawFloatBuf) = initArrays(n) | |
| println("result = " + th.pbench({ | |
| var idx = 0 | |
| var sum = 0f | |
| while(idx < n) { | |
| sum += rawArray(idx) | |
| idx += 1 | |
| } | |
| sum |
NewerOlder