Debian Codegraph @

jmh-scala-tests/src/main/scala/org/eclipse/collections/impl/jmh/GroupByScalaTest.scala

raw
1 /*
2 * Copyright (c) 2021 Goldman Sachs.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
6 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7 * and the Eclipse Distribution License is available at
8 * http://www.eclipse.org/org/documents/edl-v10.php.
9 */
10
11 package org.eclipse.collections.impl.jmh
12
13 import org.junit.Assert
14
15 import scala.collection.mutable.ArrayBuffer
16
17 object GroupByScalaTest
18 {
19 private val SIZE = 1000000
20 private val integers = new ArrayBuffer[Int](SIZE) ++ (1 to SIZE)
21
22 def groupBy_2_keys_serial_eager_scala()
23 {
24 Assert.assertEquals(2, this.integers.groupBy((each: Int) => each % 2 == 0).size)
25 }
26
27 def groupBy_100_keys_serial_eager_scala()
28 {
29 Assert.assertEquals(100, this.integers.groupBy((each: Int) => each % 100).size)
30 }
31
32 def groupBy_10000_keys_serial_eager_scala()
33 {
34 Assert.assertEquals(10000, this.integers.groupBy((each: Int) => each % 10000).size)
35 }
36
37 def groupBy_2_keys_serial_lazy_scala()
38 {
39 Assert.assertEquals(2, this.integers.view.groupBy((each: Int) => each % 2 == 0).size)
40 }
41
42 def groupBy_100_keys_serial_lazy_scala()
43 {
44 Assert.assertEquals(100, this.integers.view.groupBy((each: Int) => each % 100).size)
45 }
46
47 def groupBy_10000_keys_serial_lazy_scala()
48 {
49 Assert.assertEquals(10000, this.integers.view.groupBy((each: Int) => each % 10000).size)
50 }
51 }