Created
December 13, 2014 11:23
-
-
Save rklaehn/3e9290118fcf63d1feae to your computer and use it in GitHub Desktop.
Benchmark for SI-9043
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
import java.util | |
import ichi.bench.Thyme | |
import scala.collection.mutable.ArrayBuffer | |
object ArrayBufferInsertBench extends App { | |
val th = Thyme.warmed(verbose = println) | |
// val th = new Thyme() | |
def insertBenchmark(n:Int, k:Int) : Unit = { | |
val buffer = new ArrayBuffer[String] | |
val jbuffer = new util.ArrayList[String] | |
for (i <- 0 until n) { | |
buffer += i.toString | |
jbuffer.add(i.toString) | |
} | |
val insert = th.Warm { | |
buffer.insert(k, "x") | |
buffer.remove(k) | |
buffer.size | |
} | |
val jinsert = th.Warm { | |
jbuffer.add(k, "x") | |
jbuffer.remove(k) | |
jbuffer.size | |
} | |
th.pbenchOffWarm("insert, s.c.m.ArrayBuffer vs j.u.ArrayList")(insert)(jinsert) | |
} | |
def insertAllBenchmark(n:Int) : Unit = { | |
val sa = new ArrayBuffer[String] | |
val sb = new ArrayBuffer[String] | |
val ja = new util.ArrayList[String] | |
val jb = new util.ArrayList[String] | |
for (i <- 0 until n) { | |
sa += i.toString | |
sb += i.toString | |
ja add i.toString | |
jb add i.toString | |
} | |
val insert = th.Warm { | |
sa.clear() | |
// add at offset 0 to an empty list (best case) | |
sa.insertAll(0, sb) | |
// add at offset 0 again at the beginning of a non-empty list (worst case) | |
sa.insertAll(0, sb) | |
sa.size | |
} | |
val jinsert = th.Warm { | |
ja.clear() | |
// add at offset 0 to an empty list (best case) | |
ja.addAll(0, jb) | |
// add at offset 0 again at the beginning of a non-empty list (worst case) | |
ja.addAll(0, jb) | |
ja.size | |
} | |
th.pbenchOffWarm("insertAll, s.c.m.ArrayBuffer vs j.u.ArrayList")(insert)(jinsert) | |
} | |
insertBenchmark(10000, 9998) | |
insertAllBenchmark(10000) | |
} |
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
[info] Running ArrayBufferInsertBench | |
Creating Thyme instances and warming busywork methods... | |
done in 3.46 s | |
Warming up benchmarking... | |
done in 17.42 s | |
Warming up head-to-head benchmarking... | |
done in 45.52 s | |
Warming up computational complexity benchmarking... | |
done in 154.65 s | |
Benchmark comparison (in 8.745 s): insert, s.c.m.ArrayBuffer vs j.u.ArrayList | |
Significantly different (p ~= 0) | |
Time ratio: 0.19921 95% CI 0.19788 - 0.20054 (n=20) | |
First 110.7 ns 95% CI 110.2 ns - 111.1 ns | |
Second 22.05 ns 95% CI 21.93 ns - 22.16 ns | |
Benchmark comparison (in 16.82 s): insertAll, s.c.m.ArrayBuffer vs j.u.ArrayList | |
Significantly different (p ~= 0) | |
Time ratio: 0.10278 95% CI 0.10078 - 0.10478 (n=20) | |
First 204.2 us 95% CI 201.7 us - 206.8 us | |
Second 20.99 us 95% CI 20.68 us - 21.31 us | |
[success] Total time: 254 s, completed Dec 13, 2014 12:21:51 PM | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment