diff options
author | Martin Odersky <odersky@gmail.com> | 2007-01-03 15:56:13 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-01-03 15:56:13 +0000 |
commit | a961d3dcd6f93ee006cff1d386052bf62326739a (patch) | |
tree | 5af3312932236340708522dfd078f32beed20519 /test/files/run/collections.scala | |
parent | 02a45e20bb6f68808708dca377bc72ccaf5bba3d (diff) | |
download | scala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.gz scala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.bz2 scala-a961d3dcd6f93ee006cff1d386052bf62326739a.zip |
1.
Diffstat (limited to 'test/files/run/collections.scala')
-rwxr-xr-x | test/files/run/collections.scala | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/test/files/run/collections.scala b/test/files/run/collections.scala new file mode 100755 index 0000000000..5e97b2df38 --- /dev/null +++ b/test/files/run/collections.scala @@ -0,0 +1,100 @@ +import collection._ + +object Test extends Application { + + val printTime = false + + def sum[A](xs: Iterable[int]) = (0 /: xs)((x, y) => x + y) + + def time(op: => unit): unit = { + val start = System.currentTimeMillis; + op + if (printTime) Console.println(" time = "+(System.currentTimeMillis - start)+"ms") + } + + def test(msg: String, s0: collection.immutable.Set[int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + Console.println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, 5000) map (2*)) + Console.println("test2: "+sum(s)) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + if (s contains i) x = x + i + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.mutable.Set[int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + Console.println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, 5000) map (2*)) + Console.println("test2: "+sum(s)) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + if (s contains i) x = x + i + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.immutable.Map[int, int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + Console.println("test1: "+sum(s map (._2))) + time { + s = s ++ (List.range(0, 1000) map (x => x * 2 -> x * 2)) + Console.println("test2: "+sum(s map (._2))) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + s get i match { + case Some(i) => x = x + i + case None => + } + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.mutable.Map[int, int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + Console.println("test1: "+sum(s map (._2))) + time { + s = s ++ (List.range(0, 5000) map (x => x * 2 -> x * 2)) + Console.println("test2: "+sum(s map (._2))) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + s get i match { + case Some(i) => x = x + i + case None => + } + Console.println("test3: "+x) + } + } + + test("immutable.ListSet", new immutable.ListSet[int]) + test("immutable.TreeSet", new immutable.TreeSet[int]) + test("mutable.HashSet", new mutable.HashSet[int]) + test("immutable.ListMap", new immutable.ListMap[int, int]) + test("immutable.TreeMap", new immutable.TreeMap[int, int]) + test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[int, int]) + test("mutable.HashMap", new mutable.HashMap[int, int]) +} |