Last active
August 29, 2015 14:03
-
-
Save notyy/7f3c211e69be4aabb43a to your computer and use it in GitHub Desktop.
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
package microbenchmarks | |
import org.scalameter.PerformanceTest | |
import org.scalameter.api._ | |
import scala.collection.mutable.ArrayBuffer | |
object CollectionAppendBenchmark extends PerformanceTest.OfflineReport { | |
val sizes: Gen[Int] = Gen.range("size")(100, 500, 100) | |
var list = List.empty[Int] | |
var array = ArrayBuffer.empty[Int] | |
var vector = Vector.empty[Int] | |
performance of "Vector" in { | |
measure method ":+" in { | |
using(sizes) in { s => | |
var max = 0 | |
while(max < s) { | |
vector = vector :+ 1 | |
max += 1 | |
} | |
} | |
} | |
} | |
performance of "List" in { | |
// measure method ":+" in { | |
// using(sizes) in { s => | |
// var max = 0 | |
// while(max < s) { | |
// list = list :+ 1 | |
// max += 1 | |
// } | |
// } | |
// } | |
measure method ":: then reverse" in { | |
using(sizes) in { s => | |
var max = 0 | |
while(max < s) { | |
list = 1 :: list | |
max += 1 | |
} | |
} | |
list.reverse | |
} | |
} | |
performance of "ArrayBuffer" in { | |
measure method ":+" in { | |
using(sizes) in { s => | |
var max = 0 | |
while(max < s) { | |
array = array :+ 1 | |
max += 1 | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment