~ubuntu-branches/debian/sid/scala/sid

« back to all changes in this revision

Viewing changes to test/pending/run/t5293.scala

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Mehdi Dogguy, Lucas Satabin, Frank S. Thomas, Emmanuel Bourg
  • Date: 2015-06-05 23:52:59 UTC
  • mfrom: (1.2.11)
  • Revision ID: package-import@ubuntu.com-20150605235259-wk00vgk83dh8o19g
Tags: 2.10.5-1
* Team upload.

[ Mehdi Dogguy ]
* New upstream release (Closes: #744278).

[ Lucas Satabin ]
* Update patches
* Update the clean target
* Update paths of elements to install
* Update watch file

[ Frank S. Thomas ]
* Remove myself from Uploaders.

[ Emmanuel Bourg ]
* The package has been adopted by the Java Team (Closes: #754935)
* Patched the build to avoid downloading libraries from the Internet
* Replaced the minified JavaScript files with unobfuscated ones
* No longer build scala-partest.jar until diffutils is packaged or replaced
* debian/watch: Fixed the versions matched (x.y.z instead of x.y.z..z)
* debian/rules:
  - Added the missing get-orig-source target (Closes: #724704)
  - Improved the clean target
* debian/control:
  - Build depend on scala (>= 2.10) and bnd
  - Use canonical URLs for the Vcs-* fields
  - Standards-Version updated to 3.9.6 (no changes)
* Switch to debhelper level 9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
 
 
4
import scala.collection.JavaConverters._
 
5
 
 
6
 
 
7
 
 
8
object Test extends App {
 
9
  
 
10
  def bench(label: String)(body: => Unit): Long = {
 
11
    val start = System.nanoTime
 
12
 
 
13
    0.until(10).foreach(_ => body)
 
14
 
 
15
    val end = System.nanoTime
 
16
 
 
17
    //println("%s: %s ms".format(label, (end - start) / 1000.0 / 1000.0))
 
18
    
 
19
    end - start
 
20
  }
 
21
  
 
22
  def benchJava(values: java.util.Collection[Int]) = {
 
23
    bench("Java Set") {
 
24
      val set = new java.util.HashSet[Int]
 
25
      
 
26
      set.addAll(values)
 
27
    }
 
28
  }
 
29
 
 
30
  def benchScala(values: Iterable[Int]) = {
 
31
    bench("Scala Set") {
 
32
      val set = new scala.collection.mutable.HashSet[Int]
 
33
      
 
34
      set ++= values
 
35
    }
 
36
  }
 
37
  
 
38
  def benchScalaSorted(values: Iterable[Int]) = {
 
39
    bench("Scala Set sorted") {
 
40
      val set = new scala.collection.mutable.HashSet[Int]
 
41
      
 
42
      set ++= values.toArray.sorted
 
43
    }
 
44
  }
 
45
  
 
46
  def benchScalaPar(values: Iterable[Int]) = {
 
47
    bench("Scala ParSet") {
 
48
      val set = new scala.collection.parallel.mutable.ParHashSet[Int] map { x => x }
 
49
      
 
50
      set ++= values
 
51
    }
 
52
  }
 
53
  
 
54
  val values = 0 until 50000
 
55
  val set = scala.collection.mutable.HashSet.empty[Int]
 
56
  
 
57
  set ++= values
 
58
  
 
59
  // warmup
 
60
  for (x <- 0 until 5) {
 
61
    benchJava(set.asJava)
 
62
    benchScala(set)
 
63
    benchScalaPar(set)
 
64
    benchJava(set.asJava)
 
65
    benchScala(set)
 
66
    benchScalaPar(set)
 
67
  }
 
68
  
 
69
  val javaset = benchJava(set.asJava)
 
70
  val scalaset = benchScala(set)
 
71
  val scalaparset = benchScalaPar(set)
 
72
  
 
73
  assert(scalaset < (javaset * 8), "scalaset: " + scalaset + " vs. javaset: " + javaset)
 
74
  assert(scalaparset < (javaset * 8), "scalaparset: " + scalaparset + " vs. javaset: " + javaset)
 
75
}
 
76
 
 
77
 
 
78
 
 
79
 
 
80
 
 
81
 
 
82
 
 
83