performance - Concurrent Processing in Scala -


I am trying to use concurrent programming in Scala based on the here in the Stack Overflow, based on Project Oler Have created a program. I try three methods: There is a simple execution in which there is no paralism. Uses the java.util.concurrency API via second user and calls. Third, based on the above page, using Scala. Future My aim is to compare the execution time.

This code is:

  package sandbox import java.util.concurrent._import scala.actors._Object TestPool {def Eval (n: int): boolean = (N% 3 == 0) || (N% 5 == 0) DRF run single (Max: int): int = (up to 1 max). Filter (Aval (_)). FoldLeft (0) (_ + _) Def run pole (max: int): int = {def getCallable (i: int): callable [boolean] = new colable [boolean] {def call = eval (i)} val pool = Examiner. NewfixedThreadPool (5) val results = (up to 1 max) .Filter (i = & Gt; pool get. Get (getCallable (i)). Folded lift (0) (_ + _) pool.Shootdown pool.weitermination Mathematics.mx_long, time unit.SENDS)}} def runFutures (maximum: int): int = (up to 1 max) .filter (i = & gt; future. Eval (i)) apply) .Fold lift 0) (_ + _) / ** * f is the function to run. It gives a Tuple2 that contains the amount and * execution time. * / Df test (max: int, f: int => int): (int, long) = {well t = system syntetime millisec vale result = f (maximum) valta delta t = system serant time emilis - t ("Pool:" + test (max, max, and test) (Definition, Delta): DEF Main (Args: Array [String]): unit = {val max = 10000 println ("single:" + test (max, run single) The results are:  

Max = 10:

    Println "Futures:" + Exams (Max, Runfuture))}}

>

  • Single: (23,31)
  • < Li> Pool: (23,16)
  • Futures: (23,31)
  • Maximum = 100:

    • Single: (2318,33)
    • Pool: (2318,31)
    • Future: (2318,55)
    • Maximum = 1000:

    • Single: (23316842)
    • Pool: (233168111)
    • Futures: (233168364)
    • = 10000:

      • Single: (23331668,144)
      • Pool: (23331668, 544)
      • Future: ... I have 3 minutes After the removal was canceled

      Obviously I could not use concurre to correct ncy api from java and scala so i ask: where is my fault? What is the more appropriate way to use interactivity? And about Scala actor? Is it possible to use it?

    What are you expecting? Do you expect to do better than others than one of these methods? Are you expecting programs on different scale for different execution methods?

    How many corpses are there in your machine? If you have only one core then you should expect to increase linearly with working on time. What does your CPU use during the run? Numbers are repeatable?

    You have not taken into account the effect of JVM Hotspot warm-up time, which can cause enough problems for this kind of micro-benchmark.


    Comments

    Popular posts from this blog

    sql - dynamically varied number of conditions in the 'where' statement using LINQ -

    asp.net mvc - Dynamically Generated Ajax.BeginForm -

    Debug on symbian -