Cost of implicit conversion from java to scala collections -


i'd know cost of implicit conversion java collection scala ones. in this doc there several implicit two-way conversions said "converting source type target type , again return original source object".

i conclude cost should minor (wrapping), still how it?

i ask question because use java sets in scala code, implicitly converted scala set import asscalaset (i need in places). however, might consequent overhead little accessors such size()

does know?

i decided answer question practical point of view. used following simple jmh benchmarks test operations per second original scala collection , converted 1 (using implicit conversion).

please find below code of benchmark:

import org.openjdk.jmh.annotations._  import scala.collection.javaconversions._  @state(scope.thread) class wrapperbenchmark {    val unwrappedcollection = (1 100).toset   val wrappedcollection: java.util.set[int] = (1 100).toset[int]    @benchmark   def measureunwrapped: int = unwrappedcollection.size    @benchmark   def measurewrapped: int = wrappedcollection.size() } 

i used sbt , sbt-jmh plugin running. please find results below:

[info] benchmark                           mode  cnt          score         error  units [info] wrapperbenchmark.measureunwrapped  thrpt  200  353214968.844 ± 1534779.932  ops/s [info] wrapperbenchmark.measurewrapped    thrpt  200  284669396.241 ± 4223983.126  ops/s 

so according results, there overhead indeed. try continue research providing reason why in later update question.

please let me know if want me share complete sbt project future research.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -