Created
November 21, 2017 04:47
-
-
Save lossyrob/5ee7f16e1018875288ae11978656af90 to your computer and use it in GitHub Desktop.
Measure object size
This file contains 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
// "com.madhukaraphatak" %% "java-sizeof" % "0.1" | |
import geotrellis.vector._ | |
import com.madhukaraphatak.sizeof.SizeEstimator | |
import com.vividsolutions.jts.{geom => jts} | |
object Main { | |
def sbytes(bytes: Long, si: Boolean = false): String = { | |
val unit = if(si) { 1000 } else { 1024 } | |
if (bytes < unit) { | |
bytes + " B" | |
} else { | |
val exp = (math.log(bytes) / math.log(unit)).toInt | |
val pre = (if(si) { "kMGTPE" } else { "KMGTPE" }).charAt(exp-1) + (if(si) { "" } else { "i" }) | |
f"${bytes / math.pow(unit, exp)}%.1f ${pre}B" | |
} | |
} | |
def main(args: Array[String]): Unit = { | |
println(s"A million points: ${sbytes(SizeEstimator.estimate(Point(2,2))* 1000000)}") | |
println(s"A million JTS points: ${sbytes(SizeEstimator.estimate(Point(2,2).jtsGeom)* 1000000)}") | |
println(s"A million coords points: ${sbytes(SizeEstimator.estimate(new jts.Coordinate(2,2))* 1000000)}") | |
println(s"A million double tuples: ${sbytes(SizeEstimator.estimate((2.0, 1.0))* 1000000)}") | |
println(sbytes(SizeEstimator.estimate(Point(2,2).jtsGeom))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment