Last active
August 29, 2015 14:11
-
-
Save valdo404/82184bd4c8109f420487 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 net.openhft.koloboke.collect.map.hash.HashIntObjMaps | |
| import scala.collection.mutable | |
| object SortedMap { | |
| implicit class RichElapsed[A](f: => A) { | |
| def elapsed(): (A, Double) = { | |
| val start = System.nanoTime() | |
| val res = f | |
| val end = System.nanoTime() | |
| (res, (end-start)/1e9.toDouble) | |
| } | |
| } | |
| val size: Int = 5000000 | |
| def main(args: Array[String]) { | |
| println("Mean koko %s seconds".format(0.to(10).foreach(_ => benchKoko()).elapsed()._2 / 10)) | |
| //Mean koko 1.9130479 seconds | |
| println("Scala HashMap %s seconds".format(0.to(10).foreach(_ => benchJava()).elapsed()._2 / 10)) | |
| //Scala HashMap 0.8909204000000001 seconds | |
| println("HashMap %s seconds".format(0.to(10).foreach(_ => benchScala()).elapsed()._2 / 10)) | |
| //HashMap 3.9694762 seconds | |
| } | |
| def benchKoko() { | |
| val kokoHashMap = HashIntObjMaps.newMutableMap[String] | |
| 1.to(size).foreach(v => kokoHashMap.put(v, v.toString)) | |
| } | |
| def benchScala() { | |
| val scalaHashMap = mutable.HashMap[Int, String]() | |
| 1.to(size).foreach(v => scalaHashMap += v -> v.toString) | |
| } | |
| def benchJava() { | |
| val hashMap = new util.HashMap[Integer, String]() | |
| 1.to(size).foreach(v => hashMap.put(v, v.toString)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment