forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-3.2.2' into language-reference-stable
- Loading branch information
Showing
396 changed files
with
8,007 additions
and
2,517 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/ContendedInitialization.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.{Executors, ExecutorService} | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
class ContendedInitialization { | ||
|
||
@Param(Array("2000000", "5000000")) | ||
var size: Int = _ | ||
|
||
@Param(Array("2", "4", "8")) | ||
var nThreads: Int = _ | ||
|
||
var executor: ExecutorService = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
executor = Executors.newFixedThreadPool(nThreads) | ||
} | ||
|
||
@TearDown | ||
def cleanup: Unit = { | ||
executor.shutdown() | ||
executor = null | ||
} | ||
|
||
@Benchmark | ||
def measureContended(bh: Blackhole): Unit = { | ||
val array = Array.fill(size)(new LazyHolder) | ||
val task: Runnable = () => | ||
for (elem <- array) bh.consume(elem.value) | ||
|
||
val futures = | ||
for (_ <- 0 until nThreads) yield | ||
executor.submit(task) | ||
|
||
futures.foreach(_.get()) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/InitializedAccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class InitializedAccess { | ||
|
||
var holder: LazyHolder = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
holder = new LazyHolder | ||
holder.value | ||
} | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/InitializedAccessAny.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyAnyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class InitializedAccessAny { | ||
|
||
var holder: LazyAnyHolder = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
holder = new LazyAnyHolder | ||
holder.value | ||
} | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/InitializedAccessGeneric.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyGenericHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class InitializedAccessGeneric { | ||
|
||
var holder: LazyGenericHolder[String] = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
holder = new LazyGenericHolder[String]("foo") | ||
holder.value | ||
} | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/InitializedAccessMultiple.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class InitializedAccessMultiple { | ||
|
||
var holders: Array[LazyHolder] = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
holders = Array.fill(100){ new LazyHolder } | ||
} | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
var i = 0 | ||
while(i < 100) { | ||
val currentHolder = holders(i) | ||
bh.consume(currentHolder) | ||
bh.consume(currentHolder.value) | ||
i = i + 1 | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/InitializedAccessString.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyStringHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class InitializedAccessString { | ||
|
||
var holder: LazyStringHolder = _ | ||
|
||
@Setup | ||
def prepare: Unit = { | ||
holder = new LazyStringHolder | ||
holder.value | ||
} | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/LazyVals.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
import java.util.concurrent.CountDownLatch | ||
object LazyVals { | ||
|
||
trait Foo | ||
class Bar1 extends Foo | ||
class Bar2 extends Foo | ||
class Bar3 extends Foo | ||
class Bar4 extends Foo | ||
class Bar5 extends Bar4 | ||
|
||
class LazyStringHolder { | ||
|
||
lazy val value: String = { | ||
System.nanoTime() % 5 match { | ||
case 0 => "abc" | ||
case 1 => "def" | ||
case 2 => "ghi" | ||
case 3 => "jkl" | ||
case 4 => "mno" | ||
} | ||
} | ||
} | ||
|
||
class LazyHolder { | ||
|
||
lazy val value: List[Int] = { | ||
System.nanoTime() % 5 match { | ||
case 0 => 1 :: 2 :: Nil | ||
case 1 => Nil | ||
case 2 => 1 :: Nil | ||
case 3 => Nil | ||
case 4 => 1 :: 2 :: 3 :: Nil | ||
} | ||
} | ||
} | ||
|
||
class LazyGenericHolder[A](v: => A) { | ||
lazy val value: A = v | ||
} | ||
|
||
class LazyAnyHolder { | ||
lazy val value: Any = { | ||
System.nanoTime() % 5 match { | ||
case 0 => new Bar1 | ||
case 1 => new Bar2 | ||
case 2 => new Bar3 | ||
case 3 => new Bar4 | ||
case 4 => new Bar4 | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/UninitializedAccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class UninitializedAccess { | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
var i = 0 | ||
val holder = new LazyHolder | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
i = i + 1 | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
bench-micro/src/main/scala/dotty/tools/benchmarks/lazyvals/UninitializedAccessMultiple.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dotty.tools.benchmarks.lazyvals | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import LazyVals.LazyHolder | ||
import org.openjdk.jmh.infra.Blackhole | ||
import java.util.concurrent.TimeUnit | ||
|
||
@BenchmarkMode(Array(Mode.AverageTime)) | ||
@Fork(2) | ||
@Threads(1) | ||
@Warmup(iterations = 5) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@State(Scope.Benchmark) | ||
class UninitializedAccessMultiple { | ||
|
||
@Benchmark | ||
def measureInitialized(bh: Blackhole) = { | ||
var i = 0 | ||
while(i < 100) { | ||
val holder = new LazyHolder | ||
bh.consume(holder) | ||
bh.consume(holder.value) | ||
i = i + 1 | ||
} | ||
} | ||
} |
Oops, something went wrong.