aboutsummaryrefslogtreecommitdiff
path: root/tests/run/t3242.scala
blob: 6a8ecd7a2f3978ec736803bee6ee9ab36b60f000 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import scala.language.{ higherKinds }

object Test {

 def benchmarkA(num: Int): Unit = {

   type A = Int

   def updateM[M[_]](ms: M[A], update: (M[A], A)=>M[A]): M[A] = {
     var is = ms
     for (i <- 0 until num) is = update(is, i)
     is
   }

   //
   def vectorAppend: Vector[A] = updateM[Vector](Vector(), (as, a)=>{
     val v = (as :+ a)
     //println("==>append:    i: "+i1+", v: "+v)
     v
   })
   // this will crash, Vector bug!
   def vectorRemove(vec: Vector[A]): Vector[A] = updateM[Vector](vec, (as, a)=>{
     val v = (as filterNot{ _ == a})
     //val v = (is filter{ _ != i})
     //println("==>remove:    i: "+a)
     v
   })

   val ct = vectorAppend
   println(" append [num: "+num+"] vec")
   vectorRemove(ct)
   println(" remove [num: "+num+"] vec")
 } // BenchmarkA

 def comparison(num: Int): Unit = {
   for (i <- 1 until 5) benchmarkA(num*i)
   println(">> comparison done, num: "+num);
 }

 def main(args: Array[String]): Unit = {
   try {
     //createBenchmarkA(23).testRun

     comparison(200) // OK
     comparison(2000) // this will crach

   } catch {
     case e: Exception => e.printStackTrace()
   }
 }
}