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 pull request scala#7732 from brunnerant/tuple-split
Extend Tuple API
- Loading branch information
Showing
16 changed files
with
372 additions
and
8 deletions.
There are no files selected for viewing
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 @@ | ||
size:0,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 |
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 @@ | ||
size:0,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 |
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 @@ | ||
size:0,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 |
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
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.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Drop { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleDrop(): Tuple = { | ||
DynamicTuple.dynamicDrop(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arrayDrop(): Array[Object] = { | ||
array.drop(half) | ||
} | ||
} |
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.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Split { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleSplit(): (Tuple, Tuple) = { | ||
DynamicTuple.dynamicSplitAt(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arraySplit(): (Array[Object], Array[Object]) = { | ||
array.splitAt(half) | ||
} | ||
} |
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.tuples | ||
|
||
import org.openjdk.jmh.annotations._ | ||
import scala.runtime.DynamicTuple | ||
|
||
@State(Scope.Thread) | ||
class Take { | ||
@Param(Array("0")) | ||
var size: Int = _ | ||
var tuple: Tuple = _ | ||
var array: Array[Object] = _ | ||
var half: Int = _ | ||
|
||
@Setup | ||
def setup(): Unit = { | ||
tuple = () | ||
half = size / 2 | ||
|
||
for (i <- 1 to size) | ||
tuple = "elem" *: tuple | ||
|
||
array = new Array[Object](size) | ||
} | ||
|
||
@Benchmark | ||
def tupleTake(): Tuple = { | ||
DynamicTuple.dynamicTake(tuple, half) | ||
} | ||
|
||
@Benchmark | ||
def arrayTake(): Array[Object] = { | ||
array.take(half) | ||
} | ||
} |
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
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
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
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,14 @@ | ||
() | ||
() | ||
() | ||
(1,2,3,4,5) | ||
(2,3,4,5) | ||
(4,5) | ||
() | ||
() | ||
(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) | ||
(12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) | ||
(21,22,23,24,25,26,27,28,29,30,31,32,33,34,35) | ||
(31,32,33,34,35) | ||
() | ||
() |
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,23 @@ | ||
|
||
object Test extends App { | ||
val emptyTuple: Tuple = () | ||
val tuple: Tuple = ("1", "2", "3", "4", "5") | ||
val tupleXXL: Tuple = ("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") | ||
|
||
println(emptyTuple.drop(0)) | ||
println(emptyTuple.drop(1)) | ||
println(emptyTuple.drop(10)) | ||
|
||
println(tuple.drop(0)) | ||
println(tuple.drop(1)) | ||
println(tuple.drop(3)) | ||
println(tuple.drop(5)) | ||
println(tuple.drop(10)) | ||
|
||
println(tupleXXL.drop(0)) | ||
println(tupleXXL.drop(1)) | ||
println(tupleXXL.drop(10)) | ||
println(tupleXXL.drop(20)) | ||
println(tupleXXL.drop(25)) | ||
println(tupleXXL.drop(30)) | ||
} |
Oops, something went wrong.