Skip to content

Instantly share code, notes, and snippets.

@pchlupacek
Created November 24, 2017 17:53
Show Gist options
  • Save pchlupacek/d80a947ac4fdd6f72649a5ae57cced59 to your computer and use it in GitHub Desktop.
Save pchlupacek/d80a947ac4fdd6f72649a5ae57cced59 to your computer and use it in GitHub Desktop.
Ref perf
val refSync = async.syncRefOf[IO, Long](0l).unsafeRunSync()
val refAsync = async.refOf[IO, Long](0l).unsafeRunSync()
val count = 10000000
def time[A](s: String)(f: IO[A]): A = {
val start = System.currentTimeMillis()
val a = f.unsafeRunSync()
val took = System.currentTimeMillis() - start
println(s"Execution of : $s took ${took.toFloat/1000} s")
a
}
def op(action: IO[Unit]) : IO[Unit] = {
def go(rem: Int): IO[Unit] = {
if (rem == 0) IO.unit
else action flatMap { _ => go(rem - 1) }
}
go(count)
}
println(s"Ops: $count")
time("SYNC: setSyncPure")(op(refSync.setSyncPure(1l)))
time("SYNC: setSyncPure")(op(refSync.setSyncPure(1l)))
time("ASYNC: setSyncPure")(op(refAsync.setSyncPure(1l)))
time("SYNC: setAsyncPure")(op(refSync.setAsyncPure(1l)))
time("ASYNC: setAsyncPure")(op(refAsync.setAsyncPure(1l)))
time("SYNC: get")(op(refSync.get.void))
time("ASYNC: get")(op(refAsync.get.void))
time("SYNC: modify")(op(refSync.modify { _ => 2 }.void))
time("ASYNC: modify")(op(refAsync.modify { _ => 2 }.void))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment