Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
fcaa01a
First commit of ArrayDeque for collections-strawman
pathikrit Mar 24, 2017
834d9d7
switch to scalatest
pathikrit Mar 24, 2017
51e4f4a
upgrade scala version
pathikrit Mar 24, 2017
e6838e6
First pass through code review suggestions
pathikrit Mar 27, 2017
57dbc41
move checkIndex to companion object
pathikrit Mar 27, 2017
faba4cd
rename arrayCopy to copySliceToArray
pathikrit Mar 27, 2017
4f94cdd
break foreach+if into 2 while loops
pathikrit Mar 27, 2017
aa20b6c
change scalaversion to original
pathikrit Mar 27, 2017
fa6c7e0
DRY setting nulls
pathikrit Mar 27, 2017
436a665
make defaultInitialSize final
pathikrit Mar 27, 2017
56ca57b
remove ++=:
pathikrit Mar 27, 2017
65133dc
inline fencePost util
pathikrit Mar 27, 2017
fab70a1
use Any instead of AnyRef
pathikrit Mar 27, 2017
ebbbb2a
use array copy for larger insertAll
pathikrit Mar 27, 2017
a17f38c
faster insertAll
pathikrit Mar 27, 2017
5f137d5
switch back to using AnyRef arrays
pathikrit Mar 27, 2017
e418495
faster reverse
pathikrit Mar 27, 2017
b955281
use sizeHintIfCheap in insertAll
pathikrit Mar 27, 2017
c82c14e
fix typo
pathikrit Mar 28, 2017
aca8957
faster reverse
pathikrit Mar 28, 2017
804bf43
implement sizeHint
pathikrit Mar 28, 2017
595d6c5
downsize in removeFirst/removeLast
pathikrit Mar 28, 2017
7892282
overwrite ++=:
pathikrit Mar 29, 2017
0cde632
Add clear and shrink
pathikrit Mar 29, 2017
f7ed01c
Give user option to resize when using removeFirst/removeLast
pathikrit Mar 29, 2017
c09de3a
privatize internal constructor and state
pathikrit Mar 29, 2017
1ecaf48
faster prepend
pathikrit Mar 29, 2017
0f203ad
sliding works when windowSize > stepSize
pathikrit Jun 27, 2017
27a8e6d
Document alternative sliding
pathikrit Jun 27, 2017
49bb07a
Simplify sliding
pathikrit Jun 27, 2017
c9063c6
Make the assumingCapacity utils return this
pathikrit Jun 27, 2017
64bc294
DRY-up bitmasking
pathikrit Jun 27, 2017
185d61c
:lipstick:
pathikrit Jun 28, 2017
68c9933
First pass through code review suggestions
pathikrit Aug 7, 2017
3640fa6
Merge remote-tracking branch 'upstream/master'
pathikrit Aug 7, 2017
076d6f5
Use junit for tests
pathikrit Aug 7, 2017
42ff0e3
Switch to strawman.collection.mutable package
pathikrit Aug 7, 2017
bcab165
mimic behaviour of ArrayBuffer when count<0 and idx is out of bounds
pathikrit Aug 7, 2017
b0b6d78
do not resize if current size is fine
pathikrit Aug 7, 2017
38147a5
PoC implementations of mutable.{Stack, Queue} using mutable.ArrayDeque
pathikrit Aug 8, 2017
87ea88b
change names for private methods
pathikrit Aug 8, 2017
33c7e67
optimize prependAll and insertAll
pathikrit Aug 8, 2017
f0e8ea8
Remove dependency on Predef.scala
pathikrit Aug 9, 2017
891e519
DRY up mutable.{Stack, Queue}
pathikrit Aug 9, 2017
35ae179
Go back to Array.clone()
pathikrit Aug 9, 2017
36f27c4
Remove internal mask variable
pathikrit Aug 9, 2017
d46dd19
Optimized `++=:`
pathikrit Aug 9, 2017
6c48477
simpler bound check
pathikrit Aug 9, 2017
96d996d
Consistent naming of remove APIs
pathikrit Aug 9, 2017
1dfc995
Faster Reverse APIs
pathikrit Aug 9, 2017
2c93ade
Optimized insertAll for inserts at beginning/end
pathikrit Aug 9, 2017
2bb2c75
Remove redundant check for emptiness
pathikrit Aug 9, 2017
57b2fb6
Optimized removals
pathikrit Aug 10, 2017
1647625
Optimize insertAll
pathikrit Aug 10, 2017
360e4bf
Internal DSL for modular arithmetic
pathikrit Aug 10, 2017
959410d
Optimize removeAll()
pathikrit Aug 10, 2017
b4cdc9b
Better resize strategy for removals
pathikrit Aug 10, 2017
de9c2ec
Do not repeatedly resize smaller collections
pathikrit Aug 10, 2017
0c47056
Remove unused utils
pathikrit Aug 10, 2017
efd6a47
Do not import scala._
pathikrit Aug 10, 2017
ed1ace7
Add benchmarks
pathikrit Aug 10, 2017
7addd8b
Improve benchmarks
pathikrit Aug 11, 2017
4b54e93
Move ArrayDequeBenchmark to benchmarks module
pathikrit Aug 11, 2017
755261e
Consistent length/size usages
pathikrit Aug 12, 2017
cb35330
Merge remote-tracking branch 'upstream/master'
pathikrit Dec 9, 2017
968aa5f
Move to correct directory
pathikrit Dec 9, 2017
f832409
Add self to developers (to trigger a CI build post CLA sign check)
pathikrit Dec 9, 2017
7b2b9e1
First cut at porting to Scala 2.13
pathikrit Dec 9, 2017
8c4a20c
Move Stack/Queue to use strawman.collection.Seq
pathikrit Dec 9, 2017
92f2252
Merge branch 'master' into master
pathikrit Jan 31, 2018
d3d7155
Rename removeHeadWhile to removeWhile
pathikrit Jan 31, 2018
b8c32a6
Move peek to queue/stack APIs
pathikrit Jan 31, 2018
0519263
remove reverseIterator
pathikrit Jan 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package strawman.collection.mutable

import scala._
import scala.collection.mutable
import scala.Predef._

import java.lang.System.nanoTime

object ArrayDequeBenchmark extends App {
val candidates = Seq(
strawman.collection.mutable.ArrayDeque.empty[Int],
scala.collection.mutable.ArrayBuffer.empty[Int]
)

def benchmark[U](name: String, f: mutable.Buffer[Int] => U) = {
def profile(buffer: mutable.Buffer[Int]) = {
val t1 = nanoTime()
f(buffer)
(nanoTime() - t1)/1e6
}
println(s"===============[$name]=================")
candidates foreach (c =>
println(f"${c.getClass.getSimpleName}%12s: ${profile(c)}%8.2f ms")
)
candidates.sliding(2) foreach {case Seq(a, b) =>
assert(a == b, s"Operations are not same [$name] for ${a.getClass.getName} and ${b.getClass.getName}")
}
}

val range10m = (1 to 1e7.toInt).toArray

benchmark("Insert lots of items", _ ++= range10m)
benchmark("Drop some items from an head index", _.remove(5, 10000))
benchmark("Drop some items from a tail index", b => b.remove(b.length - 10000, 10000))
benchmark("Append lots of items one by one", b => range10m.foreach(b.+=))
benchmark("Prepend few items one by one", b => (1 to 1000).foreach(_ +=: b))
benchmark("Prepend lots of items at once", range10m ++=: _)
benchmark("Insert items near head", _.insertAll(1000, range10m))
benchmark("Reversal", _.reverse)
benchmark("Insert items near tail", b => b.insertAll(b.size - 1000, range10m))
benchmark("Sliding", _.sliding(size = 1000, step = 1000).size)
benchmark("Random indexing", b => range10m.foreach(i => if (b.isDefinedAt(i)) b(i)))
benchmark("toArray", _.toArray)
benchmark("Clear lots of items", _.clear())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that your code is more readable than JMH things but we should use JMH… Could you migrate your benchmark to JMH? You can just copy-paste another benchmark (e.g. the one for ArrayBuffer) and change a few things to make it use ArrayDeque.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep both for now..

}
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ val commonSettings = Seq(
<developers>
<developer><id>ichoran</id><name>Rex Kerr</name></developer>
<developer><id>odersky</id><name>Martin Odersky</name></developer>
<developer><id>pathikrit</id><name>Pathikrit Bhowmick</name></developer>
<developer><id>julienrf</id><name>Julien Richard-Foy</name></developer>
<developer><id>szeiger</id><name>Stefan Zeiger</name></developer>
</developers>,
Expand Down
Loading