Guest User

Untitled

a guest
Mar 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import io.fsq.common.scala.Lists._
  2. import com.foursquare.common.random.RandomUtils.chooseKItems
  3.  
  4. val list = {0 until 10000}.toList
  5. val n = 50
  6.  
  7. def time[R](block: => R): R = {
  8. val t0 = System.nanoTime()
  9. val result = block
  10. val t1 = System.nanoTime()
  11. println("Elapsed time: " + (t1 - t0) + "ns")
  12. result
  13. }
  14.  
  15. // NOTE(stpyang): this takes about 1.6 seconds
  16. time (for {
  17. i <- 0 to 10000
  18. } yield {
  19. list.sample(n)
  20. }).flatten.groupBy(identity).mapValues(_.size).toSeq.sortBy(_._1)
  21.  
  22. // NOTE(stpyang): this takes about 10 seconds
  23. time (for {
  24. i <- 0 to 10000
  25. } yield {
  26. chooseKItems(list, n)
  27. }).flatten.groupBy(identity).mapValues(_.size).toSeq.sortBy(_._1)
Add Comment
Please, Sign In to add comment