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 51
|
import scala.pickling.testing.PicklingBenchmark
import scala.util.Random
import scala.pickling._
import scala.pickling.Defaults._
import scala.pickling.binary._
// for Java Serialization:
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream, ObjectInputStream}
object TraversableIntBench extends scala.pickling.testing.PicklingBenchmark {
val coll = (1 to size).toVector
override def run() {
val pickle = coll.pickle
val res = pickle.unpickle[Vector[Int]]
}
}
object TraversableJavaIntBench extends scala.pickling.testing.PicklingBenchmark {
val coll = (1 to size).toVector
override def run() {
val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(bos)
out.writeObject(coll)
val ba = bos.toByteArray()
// println("Bytes: " + ba.length)
val bis = new ByteArrayInputStream(ba)
val in = new ObjectInputStream(bis)
val res = in.readObject.asInstanceOf[Vector[Int]]
}
}
object TraversableKryoIntBench extends scala.pickling.testing.PicklingBenchmark {
var ser: KryoSerializer = _
val coll = (1 to size).toVector
override def tearDown() {
ser = null
}
override def run() {
val rnd: Int = Random.nextInt(10)
val arr = Array.ofDim[Byte](32 * 2048 * 2048 + rnd)
ser = new KryoSerializer
val pickled = ser.toBytes(coll, arr)
val unpickled = ser.fromBytes[Vector[Int]](pickled)
}
}
|