Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io.fsq.common.scala.Lists._
- import com.foursquare.common.random.RandomUtils.chooseKItems
- val list = {0 until 10000}.toList
- val n = 50
- def time[R](block: => R): R = {
- val t0 = System.nanoTime()
- val result = block
- val t1 = System.nanoTime()
- println("Elapsed time: " + (t1 - t0) + "ns")
- result
- }
- // NOTE(stpyang): this takes about 1.6 seconds
- time (for {
- i <- 0 to 10000
- } yield {
- list.sample(n)
- }).flatten.groupBy(identity).mapValues(_.size).toSeq.sortBy(_._1)
- // NOTE(stpyang): this takes about 10 seconds
- time (for {
- i <- 0 to 10000
- } yield {
- chooseKItems(list, n)
- }).flatten.groupBy(identity).mapValues(_.size).toSeq.sortBy(_._1)
Add Comment
Please, Sign In to add comment