Skip to content

Instantly share code, notes, and snippets.

@amoghmargoor
Last active November 9, 2019 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amoghmargoor/53ca77f71dd2b9f117798372b8d38442 to your computer and use it in GitHub Desktop.
Save amoghmargoor/53ca77f71dd2b9f117798372b8d38442 to your computer and use it in GitHub Desktop.
import scala.io.Source
object IteratorTest {
def main(args:Array[String]) {
val s1 = Source.fromFile("/Users/amoghm/src/rand.txt").mkString //returns the file data as String
//splitting String data with white space and calculating the number of occurrence of each word in the file
var buf = s1.split("\\s+").map(s => s.trim.toInt)
println("buffer length " + buf.length)
val coefficients = Array(34, 45, 56, 78, 90, 32, 12, 13, 45, 56, 89, 67)
val qlp_shift = 32
var i = 0
/**
* **********************************************
* Only measuring the performance of below loop.
* **********************************************
*/
val t0 = System.nanoTime()
for (i <- 12 until buf.length) {
val delta = buf(i);
val prediction : Int = coefficients
.zip(buf.slice(i - 12, i))
.map( {
case (c, s) => c * s
}).sum >> qlp_shift
buf(i) = prediction + delta
}
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment