Created
December 18, 2014 23:29
-
-
Save drstevens/77db6bab6b1e995dac13 to your computer and use it in GitHub Desktop.
rough timing of alternate implementation of Rng.fill
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
import com.nicta.rng.Rng | |
import org.joda.time.DateTime | |
import scalaz._ | |
import Scalaz._ | |
object Foo extends App { | |
def time[A](f: => A): (Long, Long, Long) = { | |
val t0 = System.currentTimeMillis | |
val a = f | |
val t1 = System.currentTimeMillis | |
(t0, t1, t1-t0) | |
} | |
def fill[A](a: Rng[A], count: Int): Rng[List[A]] = | |
Stream.from(0).take(count).traverseU(_ => a).map(_.toList) | |
val rng = Rng.int | |
Thread.sleep(5000) | |
val a1@(s1a, e1a, ms1a) = time(fill(rng, 1000000).run.unsafePerformIO) | |
println(s"a1: $ms1a") | |
Thread.sleep(5000) | |
val b1@(s1b, e1b, ms1b) = time(rng.fill(1000000).run.unsafePerformIO) | |
println(s"b1: $ms1b") | |
Thread.sleep(5000) | |
val a2@(s2a, e2a, ms2a) = time(fill(rng, 1000000).run.unsafePerformIO) | |
println(s"a2: $ms2a") | |
Thread.sleep(5000) | |
val b2@(s2b, e2b, ms2b) = time(rng.fill(1000000).run.unsafePerformIO) | |
println(s"b2: $ms2b") | |
Thread.sleep(5000) | |
val a3@(s3a, e3a, ms3a) = time(fill(rng, 1000000).run.unsafePerformIO) | |
println(s"a3: $ms3a") | |
Thread.sleep(5000) | |
val b3@(s3b, e3b, ms3b) = time(rng.fill(1000000).run.unsafePerformIO) | |
println(s"b2: $ms3b") | |
def p(t: (Long, Long, Long)): Unit = { | |
println(s"s:${new DateTime(t._1)} e:${new DateTime(t._2)} ms: ${t._3}") | |
} | |
println("-------------------") | |
p(a1) | |
p(a2) | |
p(a3) | |
println("") | |
p(b1) | |
p(b2) | |
p(b3) | |
} | |
// a1: 18630 | |
// b1: 21453 | |
// a2: 17847 | |
// b2: 26559 | |
// a3: 15243 | |
// b2: 25351 | |
// ------------------- | |
// s:2014-12-18T18:18:45.910-05:00 e:2014-12-18T18:19:04.540-05:00 ms: 18630 | |
// s:2014-12-18T18:19:36.003-05:00 e:2014-12-18T18:19:53.850-05:00 ms: 17847 | |
// s:2014-12-18T18:20:30.417-05:00 e:2014-12-18T18:20:45.660-05:00 ms: 15243 | |
// s:2014-12-18T18:19:09.545-05:00 e:2014-12-18T18:19:30.998-05:00 ms: 21453 | |
// s:2014-12-18T18:19:58.856-05:00 e:2014-12-18T18:20:25.415-05:00 ms: 26559 | |
// s:2014-12-18T18:20:50.666-05:00 e:2014-12-18T18:21:16.017-05:00 ms: 25351 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment