0

I used Scala with Lift-Json and working fine.

when i am testing with Dummy Data for Performance check, i am getting different figures means not comparable.

here goes my performance check

Data in Rows    Weight    ForRead (ms)  Parse (ms)
10000           468.9 KB    55            441
20000           948.9 kb    96            544
30000            1.4 MB     97            563
**40000          1.9 MB    127            908**
50000            2.4 MB     90            990
100000           4.8 mb    115           1500

when i used 40k Rows dummy Data every time its showing 127-140 MS to read data but if i use 50K rows its going down to 85-90 ms.

please check my code once - here it is

implicit val formats = net.liftweb.json.DefaultFormats

val map = {
  val mb = new scala.collection.mutable.HashMap[String, Any]() with scala.collection.mutable.SynchronizedMap[String, Any]
  (1 to 40000).foreach { i =>

       mb += "dummy%s".format(i) -> List("cat1", "hash1", 100, (System.currentTimeMillis()/1000).toInt) 
  }
  mb.toMap
}

//val json1 = map.toString
val json = Extraction.decompose(map)

val jsonStrOut = Printer.pretty(JsonAST.render(json))
val fileName = "foo3.txt"

val fw = new FileWriter(fileName)
fw.write(jsonStrOut)
fw.close()
val t1 = System.currentTimeMillis()
val br : BufferedReader = new BufferedReader(new FileReader(fileName));
    val sb:StringBuilder = new StringBuilder();
      var line = br.readLine();

       while (line != null) {
           sb.append(line);
           sb.append("\n");
           line = br.readLine();
       }
       val content = sb.toString();
       br.close()


println(System.currentTimeMillis() - t1)

val obj = parse(content).asInstanceOf[JObject].values

println(System.currentTimeMillis() - t1)
println(obj("dummy4"))
     println(System.currentTimeMillis() - t1)

please provide suggestions why its showing like that.

sometimes System Performance also shows impact on performance time, i considered that also .. but same showing

Devendar
  • 323
  • 1
  • 4
  • 20

1 Answers1

1

The JVM is a highly complex piece of machinery. It constantly optimizes your code while it is being executed. Code that is being called only a few times is not being optimized as much as code that is in a tight inner loop.

The result is that you can't just write a micro benchmark by timing the execution of a block of code. At the very least you need to execute the block in question continuously for a few seconds so the just in time compiler focuses his attention to it and optimizes it. This is usually called warm up. Try your benchmark with using a proper warmup and use the more accurate System.nanoTime instead of System.currentTimeMillis, and you will see much more regular behavior.

For future tests you would be best off using an existing benchmarking framework. The most well-known is google caliper, but there is a new one especially for scala that is much less intrusive and quirky to use.

Here is a talk that covers how to write a proper microbenchmark and also shows a new microbenchmarking framework Designing for performance by Rex Kerr

And here is the github site for the project Thyme

RĂ¼diger Klaehn
  • 12,445
  • 3
  • 41
  • 57