I have scenarios where I will need to process thousands of records at a time. Sometime, it might be in hundreds, may be upto 30000 records. I was thinking of using the scala's parallel collection. So just to understand the difference, I wrote a simple pgm like below:
object Test extends App{ val list = (1 to 100000).toList Util.seqMap(list) Util.parMap(list) } object Util{ def seqMap(list:List[Int]) = { val start = System.currentTimeMillis list.map(x => x + 1).toList.sum val end = System.currentTimeMillis println("time taken =" + (end - start)) end - start } def parMap(list:List[Int]) = { val start = System.currentTimeMillis list.par.map(x => x + 1).toList.sum val end = System.currentTimeMillis println("time taken=" + (end - start)) end - start } } I expected that running in parallel will be faster. However, the output I was getting was
time taken =32 time taken=127 machine config :
Intel i7 processor with 8 cores 16GB RAM 64bit Windows 8 What am I doing wrong? Is this not a correct scenario for parallel mapping?