Skip to content

Instantly share code, notes, and snippets.

@msbaek
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save msbaek/4e6db8a3c358170d5262 to your computer and use it in GitHub Desktop.

Select an option

Save msbaek/4e6db8a3c358170d5262 to your computer and use it in GitHub Desktop.
mean, standard deviation
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics
import org.scalatest.{FlatSpec, Matchers}
import scala.io.Source
class MobileResponseTimeSpec extends FlatSpec with Matchers {
val FILE_NAME = "/Users/msbaek/Downloads/res_time.txt"
val NINETY = 90.0
val THREE_SECONDS = 3.0
val TEN_SECONDS = 10.0
"90 percentile ResponseTime" should "below 3 seconds" in {
val doubles = Source.fromFile(FILE_NAME).getLines().map(_.toDouble).filter(_ < TEN_SECONDS)
val descriptiveStatistics = new DescriptiveStatistics()
doubles.foreach(descriptiveStatistics.addValue(_))
printf("mean = %.2f\n", descriptiveStatistics.getMean)
printf("stddev = %.2f\n", descriptiveStatistics.getStandardDeviation)
printf("90p = %.2f\n", descriptiveStatistics.getPercentile(NINETY))
assert(descriptiveStatistics.getPercentile(NINETY) < THREE_SECONDS)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment