{"action":"created","issue":{"url":"https://api.github.com/repos/atemerev/skynet/issues/4","repository_url":"https://api.github.com/repos/atemerev/skynet","labels_url":"https://api.github.com/repos/atemerev/skynet/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/atemerev/skynet/issues/4/comments","events_url":"https://api.github.com/repos/atemerev/skynet/issues/4/events","html_url":"https://github.com/atemerev/skynet/issues/4","id":133546415,"number":4,"title":"Scala implementation with Futures","user":{"login":"ochrons","id":629483,"avatar_url":"https://avatars.githubusercontent.com/u/629483?v=3","gravatar_id":"","url":"https://api.github.com/users/ochrons","html_url":"https://github.com/ochrons","followers_url":"https://api.github.com/users/ochrons/followers","following_url":"https://api.github.com/users/ochrons/following{/other_user}","gists_url":"https://api.github.com/users/ochrons/gists{/gist_id}","starred_url":"https://api.github.com/users/ochrons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ochrons/subscriptions","organizations_url":"https://api.github.com/users/ochrons/orgs","repos_url":"https://api.github.com/users/ochrons/repos","events_url":"https://api.github.com/users/ochrons/events{/privacy}","received_events_url":"https://api.github.com/users/ochrons/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2016-02-14T15:03:26Z","updated_at":"2016-02-17T01:39:58Z","closed_at":null,"body":"Here's the benchmark implemented using Scala `Future`\r\n\r\n```scala\r\nimport scala.concurrent._\r\nimport scala.concurrent.ExecutionContext.Implicits.global\r\nimport scala.concurrent.duration._\r\n\r\nobject Root extends App {\r\n  def skynet(num: Int, size: Int, div: Int): Future[Long] = {\r\n    if(size == 1)\r\n\t  Future.successful(num.toLong)\r\n\telse {\r\n\t  Future.sequence((0 until div).map(n => skynet(num + n*(size/div), size/div, div))).map(_.sum)\r\n\t}\r\n  }\r\n  val startTime = System.currentTimeMillis()\r\n  val x = Await.result(skynet(0, 1000000, 10), 10.seconds)\r\n  val diffMs = System.currentTimeMillis() - startTime\r\n  println(s\"Result: $x in $diffMs ms.\")\r\n}\r\n```\r\n\r\nRuns in 250ms on my i7 laptop. For comparison the Akka version takes about 8200ms and Go takes about 750ms.\r\n"},"comment":{"url":"https://api.github.com/repos/atemerev/skynet/issues/comments/184967791","html_url":"https://github.com/atemerev/skynet/issues/4#issuecomment-184967791","issue_url":"https://api.github.com/repos/atemerev/skynet/issues/4","id":184967791,"user":{"login":"sergey-scherbina","id":1105811,"avatar_url":"https://avatars.githubusercontent.com/u/1105811?v=3","gravatar_id":"","url":"https://api.github.com/users/sergey-scherbina","html_url":"https://github.com/sergey-scherbina","followers_url":"https://api.github.com/users/sergey-scherbina/followers","following_url":"https://api.github.com/users/sergey-scherbina/following{/other_user}","gists_url":"https://api.github.com/users/sergey-scherbina/gists{/gist_id}","starred_url":"https://api.github.com/users/sergey-scherbina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergey-scherbina/subscriptions","organizations_url":"https://api.github.com/users/sergey-scherbina/orgs","repos_url":"https://api.github.com/users/sergey-scherbina/repos","events_url":"https://api.github.com/users/sergey-scherbina/events{/privacy}","received_events_url":"https://api.github.com/users/sergey-scherbina/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T01:39:58Z","updated_at":"2016-02-17T01:39:58Z","body":"@tuxychandru There is fully sequential version\r\n\r\nobject SkynetSync extends App {\r\n\r\n  def skynet(num: Int, size: Int, div: Int): Long =\r\n    if (size > 1) (0 until div).map(i =>\r\n      skynet(num + i * size / div, size / div, div)).sum\r\n    else num\r\n\r\n  def run(n: Int): Long = {\r\n    val start = System.nanoTime()\r\n    val x = skynet(0, 1000000, 10)\r\n    val time = (System.nanoTime() - start) / 1000000\r\n    println(s\"$n. Result: $x in $time ms.\")\r\n    time\r\n  }\r\n\r\n  println(s\"Best time ${(0 to 10) map (run) min} ms.\")\r\n}\r\n\r\nand it works in ~50ms:\r\n\r\n0. Result: 499999500000 in 209 ms.\r\n1. Result: 499999500000 in 73 ms.\r\n2. Result: 499999500000 in 227 ms.\r\n3. Result: 499999500000 in 131 ms.\r\n4. Result: 499999500000 in 70 ms.\r\n5. Result: 499999500000 in 72 ms.\r\n6. Result: 499999500000 in 160 ms.\r\n7. Result: 499999500000 in 57 ms.\r\n8. Result: 499999500000 in 59 ms.\r\n9. Result: 499999500000 in 58 ms.\r\n10. Result: 499999500000 in 51 ms.\r\nBest time 51 ms."}}