@@ -22,7 +22,6 @@ import org.msgpack.core.buffer.{ChannelBufferOutput, OutputStreamBufferOutput}
2222import org .msgpack .value .ValueFactory
2323import xerial .core .io .IOUtil
2424
25- import scala .compat .Platform
2625import scala .util .Random
2726
2827/**
@@ -238,22 +237,29 @@ class MessagePackerTest
238237 }
239238
240239 " pack a lot of String within expected time" in {
241- val count = 500000
240+ val count = 20000
242241
243- def measureDuration (outputStream : java.io.OutputStream ) : Long = {
242+ def measureDuration (outputStream : java.io.OutputStream ) = {
244243 val packer = MessagePack .newDefaultPacker(outputStream)
245- val start = Platform .currentTime
246- for (i <- 0 to count) {
244+ var i = 0
245+ while (i < count) {
247246 packer.packString(" 0123456789ABCDEF" )
247+ i += 1
248248 }
249249 packer.close
250- Platform .currentTime - start
251250 }
252251
253- val baseDuration = measureDuration(new ByteArrayOutputStream ())
254- val (_, fileOutput) = createTempFileWithOutputStream
255- val targetDuration = measureDuration(fileOutput)
256- targetDuration shouldBe <= (baseDuration * 3 )
252+ val t = time(" packString into OutputStream" , repeat = 10 ) {
253+ block(" byte-array-output-stream" ) {
254+ measureDuration(new ByteArrayOutputStream ())
255+ }
256+
257+ block(" file-output-stream" ) {
258+ val (_, fileOutput) = createTempFileWithOutputStream
259+ measureDuration(fileOutput)
260+ }
261+ }
262+ t(" file-output-stream" ).averageWithoutMinMax shouldBe < (t(" byte-array-output-stream" ).averageWithoutMinMax * 4 )
257263 }
258264 }
259265
0 commit comments